c# - how to insert data from database in combox -


i'm trying insert data database in combo box showing tables in combobox here's connection

private void form1_load(object sender, eventargs e) {      string connetionstring = null;      sqlconnection cnn;      connetionstring = "data source=itworksdev01;initial catalog=itworksdev";      cnn = new sqlconnection(connetionstring);       (int = 0; < 5; i++)      {          combobox1.items.add(i.tostring());      }  } 

first of all, database-type using ?

you can look-up correct connection-code each database here: http://www.connectionstrings.com/

second, don't forget open connection:

private void form1_load(object sender, eventargs e) {      string connetionstring = null;      connetionstring = "data source=itworksdev01;initial catalog=itworksdev";      using (sqlconnection cnn = new sqlconnection(connetionstring))      {          cnn.open(); 

after opened connection, create datareader , sql-statement:

sqldatareader , sqlcommand

     } } 

closing/disposing isn't needed here, using makes job you.

but stackoverflow not place write code, have write , if errors can you.

good luck!


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -