.net - The error says "The ConnectionString property has not been initialized" in c# -


this code combo box want select index show textboxes.

private void combobox2_selectedindexchanged(object sender, eventargs e) {     try     {         conn.open();         cmd.connection = conn;         string query = "select * guestinfo groomno= '" + combobox2.text + "'";         db.connectdb();         db.da.selectcommand = new oledbcommand(query, db.conn);         db.executeqrycommand(query, false);         maxrecord = db.ds.tables[0].rows.count;         loadrecords(recordcounter);         cmd.commandtext = query;          dr = cmd.executereader();         while (dr.read())         {             textbox1.text = dr["gname"].tostring();             textbox2.text = dr["gcontactno"].tostring();         }         conn.close();     }     catch (exception er)     {         messagebox.show("error! " + er.message);     } } 

//my program running not in section. :(

you have define connection string connection, here suggest 1 best method executing command.

using (oledbconnection conn = new oledbconnection("yourconnectionstring"))   {      conn.open();      using (oledbcommand  cmd =new oledbcommand("your query text",  conn))        {          // execute command        }  } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -