Hello,
I have a form with tabcontrol. I want depending on the value in the textBox in the form, to fill the datagridview in the tabcontrol. I wrote this code and got the error:"No value given for one or more required parameters"
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
dateTimePicker2.Focus();
OleDbCommand command3 = new OleDbCommand();
command3.Connection = conn;
command3.CommandText = "SELECT * from Avt where Brdog=?";
command3.Parameters.AddWithValue("@Brgod", textBox1.Text);
conn.Open();
DataSet1 _dataset = new DataSet1();
OleDbDataAdapter oleDbAdapter1 = new OleDbDataAdapter(new OleDbCommand(command3.CommandText, conn));
command3.ExecuteNonQuery();
_dataset.Clear();
oleDbAdapter1.Fill(_dataset, "Avt");
dataGridView1.DataSource = _dataset.Tables["Avt"].DefaultView;
conn.Close();
}
}
But I don't have an idea why I get this error when I give the parameter value in the bold sentence.
Can anybody help me please what could be the problem? Thanks
Loading

Pravin GhadgeRank #1,340 · 1.3K reputationPosted Feb 2, 2012, 1:39 AM EST
Error may be in ur Select query. u have not specify the single quot .
command3.CommandText = "SELECT * from Avt where Brdog='?'"
VulpesRank #55 · 29.2K reputationPosted Feb 2, 2012, 1:36 AM EST
If you're wanting Brdog to match any single character, I'd try:
command3.CommandText = "SELECT * from Avt where @Brdog like '?'";
NelRank #2,060 · 702 reputationPosted Feb 2, 2012, 2:05 AM EST
NelRank #2,060 · 702 reputationPosted Feb 2, 2012, 2:21 AM EST
Now, the table in the datagridview is diplayed, but is empty. Do you have an idea why, and can you tell me please? Maybe that is because the textbox which value I pass is out of the tabcontrol?
Thank you to both of you, Pravin and Vulpes.
VulpesRank #55 · 29.2K reputationPosted Feb 2, 2012, 5:24 AM EST
http://www.c-sharpcorner.com/Forums/Thread/159991/datagridview-in-the-tabcontrol-displays-empty-rows.aspx