I need to search tables in combobox1 with the text user will enter in autoCompleteTextbox1 and it can be itemcode or itemname
but I get error says:
Additional information: The variable name '@name' has already been declared. Variable names must be unique within a query batch or stored procedure.
if (cn.State == ConnectionState.Closed)
{
cn.Open();
}
cm.Connection = cn;
if (autoCompleteTextbox1.Text == "")
{
}
else
{
AutoCompleteStringCollection namecollection = new AutoCompleteStringCollection();
string searchFor = "%" + autoCompleteTextbox1.Text + "%"; //the string the user entered.
string tableName = comboBox1.Text;
cm.CommandText = @"SELECT distinct(itmcode+''+itmname) AS name FROM " + tableName + " WHERE itmcode Like @name OR itmname LIKE @name";
cm.Parameters.AddWithValue("@name", searchFor);
SqlDataReader rea = cm.ExecuteReader();
if (rea.HasRows == true)
{
while (rea.Read())
namecollection.Add(rea["name"].ToString());
}
rea.Close();
autoCompleteTextbox1.AutoCompleteMode = AutoCompleteMode.Suggest;
autoCompleteTextbox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
autoCompleteTextbox1.AutoCompleteCustomSource = namecollection;
what is the error in my code and how to fix it plz