7
Answers

Problem with SQL(Oledb) code

mark  webb

mark webb

14y
2.3k
1

Hey,
Im doing a project working within visual studio 2008 using oledb
the following code should actually work but it seems to be breaking out just after creating the dataset and I can't seem to find any reason for this.
What its trying to do is sort one drop down box (cb_CliOrdID) based on what is selected within the other (cb_ClientName).
    private void cb_ClientName_SelectedIndexChanged(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.JET.OLEDB.4.0;" + @";Data Source=D:\Computing\Computing Project\Backup\RosieBookingandInvoiceBackup\Server\RosieBIDB.mdb;");

DataSet ds = new DataSet("Orders");
OleDbDataAdapter dsa = new OleDbDataAdapter();

dsa.SelectCommand.CommandText = @"SELECT Date_of_Order FROM tbl_Order WHERE Client_Name = '" + cb_ClientName.DisplayMember + "'";
dsa.TableMappings.Add("tbl_Order", "Orders");
dsa.Fill(ds);
cb_CliOrdID.DisplayMember = ds.Tables[0].Columns[0].ToString() ;
cb_CliOrdID.ValueMember = ds.Tables[0].Columns[0].ToString();
cb_ClientName.Refresh();

}


Would appriciate any possible help,

and thanks in advance.

Mark
Answers (7)