【发布时间】:2013-02-04 19:12:50
【问题描述】:
我想详细搜索一个名字..这是搜索按钮的代码
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;
}
所以我需要关于第一个代码的帮助
【问题讨论】:
-
您在 3 小时内问了两次基本相同的问题。 stackoverflow.com/questions/14695282/…。不要那样做