重複の可能性:
C#のデータベースで文字列を検索する方法
名前を詳しく検索したい..それが検索ボタンのコードです
private void button1_Click(object sender, EventArgs e)
{
string connectionString = Tyres.Properties.Settings.Default.Database1ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
DataTable dt = new DataTable();
SqlDataAdapter SDA = new SqlDataAdapter("SELECT * FROM table1 where Details like" + textBox1.Text, conn);
SDA.Fill(dt);
dataGridView1.DataSource = dt;
}
エラーが発生しました:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
追加情報:「likeelie」の近くで、条件が予期されるコンテキストで指定された非ブール型の式。
私はこのコードを試して整数(Quantityなど)を検索しましたが、これは私にとってうまく機能します:
private void button1_Click(object sender, EventArgs e)
{
string connectionString = Tyres.Properties.Settings.Default.Database1ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
DataTable dt = new DataTable();
SqlDataAdapter SDA = new SqlDataAdapter("SELECT * FROM table1 where Quantity like" + int.parse(textBox1.Text), conn);
SDA.Fill(dt);
dataGridView1.DataSource = dt;
}
だから私は最初のコードで助けが必要です