Senthil Gopi

Senthil Gopi

  • NA
  • 5
  • 2.4k

How to define common odbc connection??

Oct 11 2012 2:31 AM
Hi 
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(); 

Answers (4)