Hello,
I have two comboboxes on my windows form. When loading it, I want the second box to display only the values for which one of the fields from the database are the same as the displayed value in the first combobox.
I tried with this code:
command3.CommandText = "Select * from Komintent order by Komintent asc";
command2.CommandText = "Select * from Dogovor where Komintent=? order by Brdog"; //I use this command to fill the second combobox
command2.Parameters.AddWithValue("@Komintent", comboBox3.Items[0]);
and I got this error:
InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index
in the bold line above.
Could anybody please help me how to display only filtered data in the second combobox?
Thank you very much in advance.
Loading
NelPosted Feb 8, 2012, 7:01 AM
"No value given for one or more required parameters."
Krishna GaradPosted Feb 8, 2012, 6:18 AM
com1.Parameters.AddWithValue("@Komint", comboBox3.SelectedItem.Text.ToString());
or
com1.Parameters.AddWithValue("@Komint", comboBox3.SelectedValue.ToString());
NelPosted Feb 8, 2012, 6:14 AM
Krishna GaradPosted Feb 8, 2012, 5:31 AM
private void comboBox3_SelectionChangeCommitted(object sender, EventArgs e)
{
DataSet3 _dataset = new DataSet3();
OleDbCommand com1 = new OleDbCommand();
com1.CommandText = "Select * from Dogovor where Komint=@Komint order by Brdog";
com1.Parameters.AddWithValue("@Komint", comboBox3.SelectedItem);
OleDbDataAdapter oleDBDataAdapter1 = new OleDbDataAdapter(new OleDbCommand(com1, conn));
try
{
oleDBDataAdapter1.Fill(_dataset, "Komint");
//here you are making mistake before filling dataset you are trying to bind it to combo first fill the dataset and then bind it.
comboBox2.DataSource = _dataset.Tables["Dogovor"];
comboBox2.DisplayMember = "Brdog";
}
finally
{
}
textBox1.Focus();
}
NelPosted Feb 8, 2012, 5:20 AM
Krishna GaradPosted Feb 8, 2012, 5:11 AM
com1.CommandText = "Select * from Dogovor where Komint=@Komint order by Brdog";
com1.Parameters.AddWithValue("@Komint", comboBox3.SelectedItem);
NelPosted Feb 8, 2012, 5:07 AM
private void comboBox3_SelectionChangeCommitted(object sender, EventArgs e)
{
DataSet3 _dataset = new DataSet3();
OleDbCommand com1 = new OleDbCommand();
com1.Connection = conn;
com1.CommandText = "Select * from Dogovor where Komint=? order by Brdog";
com1.Parameters.AddWithValue("@Komint", comboBox3.SelectedItem);
OleDbDataAdapter oleDBDataAdapter1 = new OleDbDataAdapter(new OleDbCommand(com1.CommandText, conn));
try
{
conn.Open();
com1.ExecuteNonQuery();
comboBox2.DataSource = _dataset.Tables["Dogovor"];
comboBox2.DisplayMember = "Brdog";
oleDBDataAdapter1.Fill(_dataset, "Komint");
}
finally
{
conn.Close();
}
textBox1.Focus();
}
and get the following error on the bold line:
"Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done."
Krishna GaradPosted Feb 8, 2012, 4:28 AM