-1
I am trying to do a name search inside an Excel spreadsheet, by code works normal, but I would like to search by name, when I do the search with the abix code, returns the error:
private void button2_Click(object sender, EventArgs e)
{
try
{
_oleCmd.CommandText = "SELECT Nome FROM [Designa$] Where Nome=" + textBox1.Text;
OleDbDataReader reader = _oleCmd.ExecuteReader();
while (reader.Read())
{
textBox2.Text = reader.GetString(1);
}
reader.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,this.Text,MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Apart from the lack of quotes you need to "escape" the value passed to query.
– Guilherme Nascimento