I'm new to .net , I'm creating a new windows application, i have 3 forms in it, all the forms will have related to database execution, so every time do i need to define same set of odbc connection or there any function to create it as common and can be called by the all the forms??
OdbcConnection dbcon = new OdbcConnection("Driver={IBM DB2 ODBC DRIVER};DBALIAS=TEST;Uid=db2admin;Pwd=xingmpeg;");
OdbcCommand cmd;
OdbcDataAdapter oda;
DataSet ds;
dbcon.Open();
string dbcmd = "Select * from tbl_login where u_name = '" + textBox1.Text + "'";
cmd = new OdbcCommand(dbcmd, dbcon);
oda = new OdbcDataAdapter();
ds = new DataSet();
oda.SelectCommand = cmd;
oda.Fill(ds);
dbcon.Close(); 
Senthil GopiPosted Oct 11, 2012, 9:18 AM
Satyapriya NayakPosted Oct 11, 2012, 5:43 AM
Senthil GopiPosted Oct 11, 2012, 5:21 AM
R ACHUTHAPosted Oct 11, 2012, 4:08 AM
you can put the connection string in App.config file and use it when ever it's need.
refer the below url further more.
http://www.codeproject.com/Articles/28699/How-to-Store-and-Retrieve-a-ConnectionString-from