connecting with ADO.Net.....
Posted on 2006-05-09
I'm new in C# , ADO.NET and OOP.
In my project there are some forms which have the same ListBox
(i meen ListBox that populate the same data from a table).
In one of the forms i wrote in the Load Event this code:
private void frmWorkersRcrmnt_Load(object sender, System.EventArgs e)
SqlConnection con = new SqlConnection();
con.ConnectionString="data source=(local);initial catalog=Mashavit;integrated security=sspi";
SqlCommand com = new SqlCommand("select SourceName from
SqlDataReader dr = com.ExecuteReader();
it works great and data from the table populates the ListBox.
i know that in OOP programing i'm not soppose to put this code in each form in the Load Event in order to populate the ListBoxes. i think that i soppose to create a class called lets say: "conn"
and put there the connection lines from the code i put in the Load Event and in the form only the lines that deals with the sql lines ant the While loop.
My question is how do i do this? (because i didn't succedd doing it), what is the best way and the simpliest way to do it?