4
Reply

How to define common odbc connection??

Ask a question
Senthil Gopi

Senthil Gopi

11y
2.1k
1
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)