Jelmer Posted January 11, 2006 Posted January 11, 2006 Hello Programmers, I'll like to build a big program. But i have some little problems. I'll use classes in my program. So for every 'thing' like customers is a seporate class. In the class i can make a new user and i can add that user to the database. Something like this: public class customers { int ID; string Bedrijf,Contactpersoon,Adres,Postcode,Plaats,Tel,Mobiel,Fax,Email,Website,KVK,BTW,Debiteurnr, Opmerkingen; public customers(int id,string bedrijf,string contactpersoon,string adres,string postcode,string plaats,string tel,string mobiel,string fax,string email,string website,string kvk,string btw,string debiteurnr,string opmerkingen) { // // TODO: Add constructor logic here // ID = id; Bedrijf = bedrijf; Contactpersoon = contactpersoon; Adres = adres; Postcode = postcode; Plaats = plaats; Tel = tel; Mobiel = mobiel; Fax = fax; Email = email; Website = website; KVK = kvk; BTW = btw; Debiteurnr = debiteurnr; Opmerkingen = opmerkingen; } static OleDbConnection dbase(OleDbConnection Connection){ IniFile ini = new IniFile("test.ini"); string database; database = ini.IniReadValue("Info","Database"); string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;"; connectionString += @"Data Source=" + database + ";"; Connection.ConnectionString = connectionString; Connection.Open(); return Connection; } public void insert() { try { OleDbConnection Connection = new OleDbConnection(); Connection = dbase(Connection); // Create an OleDb command, OleDbCommand command = new OleDbCommand(); command.Connection = Connection; command.CommandText = "insert into Bedrijven (Bedrijf,Contactpersoon,Adres,Postcode,Plaats,Tel,Mobiel,Fax,Email,Website,kvk,btw,debiteurnr,opmerkingen) values('" + Bedrijf + "','" + Contactpersoon + "','" + Adres + "','" + Postcode + "','" + Plaats + "','" + Tel + "','" + Mobiel + "','" + Fax + "','" + Email + "','" + Website + "','" + KVK + "','" + BTW + "','" + Debiteurnr + "','" + Opmerkingen + " ') "; command.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } } } I like to read the database and make a list of alll customers. I thought like this: - make a SQL query like select * from customers - a for loop - for every record fill the class (class array). - read the class and add the properties to a listbox - the class has methods like .save etc. to save changes to the good directory Is this good thinking ??? Or is it to complex.... I like to use the classes on multiple forms... Gr. Jelmer Quote
Cags Posted January 11, 2006 Posted January 11, 2006 I like to read the database and make a list of alll customers. I thought like this: - make a SQL query like select * from customers - a for loop - for every record fill the class (class array). - read the class and add the properties to a listbox - the class has methods like .save etc. to save changes to the good directory Is this good thinking ??? Or is it to complex.... Certainly sounds like a reasonable method to me. Alot depends on what you are planning on doing with the data once you have loaded it from the database. If all you needed was a list of the customers (and perhaps their information) there would be no real need to create a class. But if you plan on doing various operations to them from within you application then it sounds like you have the right idea. Quote Anybody looking for a graduate programmer (Midlands, England)?
Jelmer Posted January 11, 2006 Author Posted January 11, 2006 i am busy building a billing program. for invoices ? (don't know if its a correct english word). The program can create bills for customers. And you can search bills later. I'll use the class later in the program again... Like search options.. i give the id and the program returns the class with all user things the database know. Quote
Cags Posted January 11, 2006 Posted January 11, 2006 In that case it sounds like your doing the right thing. (Note. I'm not actually a professional (yet), somebody else might give you different advice) Quote Anybody looking for a graduate programmer (Midlands, England)?
Leaders snarfblam Posted January 11, 2006 Leaders Posted January 11, 2006 Sounds like you get the idea of object oriented programming. To keep it from being complex you just need to keep it clear in your head (and in the code) of how classes interact with eachother. If a class gets too complicated, break it down into multiple classes (i.e. an invoice class could be broken down into a CustomerIdentity class, a ServicesRendered class, and a PaymentMethod class). Quote [sIGPIC]e[/sIGPIC]
Diesel Posted January 12, 2006 Posted January 12, 2006 Use the designer and create a database connection object. Create a dataAdapter and a dataset. Enter the select query for the dataAdapter. Fill the dataset. Put a datagrid onto the form. Load the dataset into the datagrid. You can do all searching from the dataset. I bolded the keywords. Look them up on msdn if you need some sample code. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.