-1

I'm trying to insert data from my database in a combo box specifically showing all my tables in the combobox here's my 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);

     for (int i = 0; i < 5; i++)
     {
         comboBox1.Items.Add(i.ToString());
     }
 }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Amped
  • 1
  • 1

1 Answers1

1

First of all, which database-type are you using ?

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

Second, don't forget to open the 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 you opened the connection, create a DataReader and a SQL-Statement:

SqlDataReader and SqlCommand

     }
}

Closing/Disposing isn't needed here, using makes that job for you.

But stackoverflow is not a place where we write you the code, you have to write it by yourself and if you get errors we can help you.

Good luck!

Community
  • 1
  • 1
DatRid
  • 1,169
  • 2
  • 21
  • 46