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 GhadgePosted Feb 2, 2012, 6:39 AM
Error may be in ur Select query. u have not specify the single quot .
command3.CommandText = "SELECT * from Avt where Brdog='?'"
VulpesPosted Feb 2, 2012, 10:24 AM
http://www.c-sharpcorner.com/Forums/Thread/159991/datagridview-in-the-tabcontrol-displays-empty-rows.aspx
NelPosted Feb 2, 2012, 7:21 AM
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.
NelPosted Feb 2, 2012, 7:05 AM
VulpesPosted Feb 2, 2012, 6:36 AM
If you're wanting Brdog to match any single character, I'd try:
command3.CommandText = "SELECT * from Avt where @Brdog like '?'";