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

Krishna GaradRank #191 · 12.8K reputationPosted Feb 7, 2012, 11:28 PM EST
NelRank #2,060 · 702 reputationPosted Feb 8, 2012, 12:07 AM EST
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 GaradRank #191 · 12.8K reputationPosted Feb 8, 2012, 12:11 AM EST
com1.CommandText = "Select * from Dogovor where Komint=@Komint order by Brdog";
com1.Parameters.AddWithValue("@Komint", comboBox3.SelectedItem);
NelRank #2,060 · 702 reputationPosted Feb 8, 2012, 12:20 AM EST
Krishna GaradRank #191 · 12.8K reputationPosted Feb 8, 2012, 12:31 AM EST
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();
}
NelRank #2,060 · 702 reputationPosted Feb 8, 2012, 1:14 AM EST
Krishna GaradRank #191 · 12.8K reputationPosted Feb 8, 2012, 1:18 AM EST
com1.Parameters.AddWithValue("@Komint", comboBox3.SelectedItem.Text.ToString());
or
com1.Parameters.AddWithValue("@Komint", comboBox3.SelectedValue.ToString());
NelRank #2,060 · 702 reputationPosted Feb 8, 2012, 2:01 AM EST
"No value given for one or more required parameters."