0

hello,
I want to open a new connection in main() instead of openning it each I need to read or save something on the database.
I opened the connection in main() but the problem is how to use it in the form? Do I have to pass it as a parameter to the form or what?

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by suneye
0

hello,
I am making a connection:

 string con = "Data Source=HUSSEIN-PC\\SQL;Initial Catalog=Images_DB;Integrated Security=True";
 SqlConnection s = new SqlConnection(con);
            s.Open();

I want to use "s" in my methods in the form,waht I must do?

0

Create a custon class. Inside of it create a method in which type this code of yours. Then instantiate the class ones, and pass (use) the referecne of class on multiple places to access to method (which will execute the sqlconnection and open it).

0

ok thank you , I still have a question .
I am trying to sort items in listview that I am reading fro database. I used listview1.sort(); but the items in the listview are not sorted why?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.