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?

Recommended Answers

All 4 Replies

hi,
pass what exactly?

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?

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).

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.