G
Guest
i made tow combobox one of them filled in page load and the other one fill
when the user select a value form the First one but i got this error:
"The Column prefix 'System.Data' does not match with a table name or alias
name used in the query"
and this my code:
the First Combobox:
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = DB.ConnectionSTR(DB.Current_DB());
SqlCommand cmd = cnn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select Client_ID,Client_Name From Client";
SqlDataAdapter da = new SqlDataAdapter();
DataTableMapping TblMap;
DataColumnMapping ColMap;
TblMap = da.TableMappings.Add("Client","Client");
ColMap = TblMap.ColumnMappings.Add("Client_ID","Client_ID");
ColMap = TblMap.ColumnMappings.Add("Client_Name","Client_Name");
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds,"Client");
cboClient_Name.DataSource = ds;
cboClient_Name.DisplayMember = "Client.Client_Name";
cboClient_Name.ValueMember = "Client.Client_ID";
The Seconde combobox:
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = DB.ConnectionSTR(DB.Current_DB());
SqlCommand cmd = cnn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select MSA_ID,MSA_Effective_Date From MSA Where
Client_ID="+cboClient_Name.SelectedValue.ToString()+"";
SqlDataAdapter da = new SqlDataAdapter();
DataTableMapping TblMap;
DataColumnMapping ColMap;
TblMap = da.TableMappings.Add("MSA","MSA");
ColMap = TblMap.ColumnMappings.Add("MSA_ID","MSA_ID");
ColMap = TblMap.ColumnMappings.Add("MSA_Effective_Date","MSA_Effective_Date");
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds,"MSA");
cboClient_Name.DataSource = ds;
cboClient_Name.DisplayMember = "MSA.Client_Name";
cboClient_Name.ValueMember = "MSA.Client_ID";
when the user select a value form the First one but i got this error:
"The Column prefix 'System.Data' does not match with a table name or alias
name used in the query"
and this my code:
the First Combobox:
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = DB.ConnectionSTR(DB.Current_DB());
SqlCommand cmd = cnn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select Client_ID,Client_Name From Client";
SqlDataAdapter da = new SqlDataAdapter();
DataTableMapping TblMap;
DataColumnMapping ColMap;
TblMap = da.TableMappings.Add("Client","Client");
ColMap = TblMap.ColumnMappings.Add("Client_ID","Client_ID");
ColMap = TblMap.ColumnMappings.Add("Client_Name","Client_Name");
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds,"Client");
cboClient_Name.DataSource = ds;
cboClient_Name.DisplayMember = "Client.Client_Name";
cboClient_Name.ValueMember = "Client.Client_ID";
The Seconde combobox:
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = DB.ConnectionSTR(DB.Current_DB());
SqlCommand cmd = cnn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select MSA_ID,MSA_Effective_Date From MSA Where
Client_ID="+cboClient_Name.SelectedValue.ToString()+"";
SqlDataAdapter da = new SqlDataAdapter();
DataTableMapping TblMap;
DataColumnMapping ColMap;
TblMap = da.TableMappings.Add("MSA","MSA");
ColMap = TblMap.ColumnMappings.Add("MSA_ID","MSA_ID");
ColMap = TblMap.ColumnMappings.Add("MSA_Effective_Date","MSA_Effective_Date");
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds,"MSA");
cboClient_Name.DataSource = ds;
cboClient_Name.DisplayMember = "MSA.Client_Name";
cboClient_Name.ValueMember = "MSA.Client_ID";