Hi guys

I'm a newbie, and can't figure out the problem with the following code. I get the error inthe line in Bold. Please help

private void Form1_Load(object sender, EventArgs e)
        {
            con = new SqlConnection();
            con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\KAMESH\\Documents\\Visual Studio 2010\\Projects\\bankDBApp\\bankDBApp\\bankAcc.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
            con.Open();
            MessageBox.Show("Connecting to SQL Database", "Connecting");
            ds = new DataSet();
            string sql = "SELECT * FROM AccountInfo";
            da = new SqlDataAdapter(sql, con);
            da.Fill(ds, "Accounts");
            [B]foreach (DataRow dr in ds.Tables["AccountInfo"].Rows)[/B] 
            {
            accountNumber = (string) dr["AccountNumber"];
            cbAccountNumber.Text = accountNumber;
            }

            acc.AccountNumber = int.Parse(accountNumber);
            cbAccountNumber.Items.Add(accountNumber);
            con.Close();

        }
da.Fill(ds, "Accounts");
foreach (DataRow dr in ds.Tables["AccountInfo"].Rows)

This is taken from your code. You tell the SqlDataAdapter to fill the dataset with a table named "Accounts", then you (in the foreach) ask for the rows from the "AccountInfo" table. There is no AccountInfo table, it doesn't matter what your SQL says.

Thanks, feel really silly now. All fixed up, now for the next problem. hopefully I don't need to post another question here.

This question has already been answered. Start a new discussion instead.