首页 > 解决方案 > 如何创建搜索按钮或如何使用文本框对数据库进行行过滤?

问题描述

我使用了 youtube 上提供的代码。他们俩都不工作

connection.Open();

OleDbCommand command = connection.CreateCommand();

command.CommandType = CommandType.Text;

command.CommandText = "select * from Table2 where Last_Name ='" + textBox12 + "'";

command.ExecuteNonQuery();

DataTable dt = new DataTable();

OleDbDataAdapter da = new OleDbDataAdapter(command);

da.Fill(dt);

dataGridView1.DataSource = dt;

connection.Close();

将出现一条错误消息,指出

“未找到列”或“缺少操作数”

标签: c#winformsms-access

解决方案


Textbox12.Text,并使用 Like 代替 =

更具可读性: $"select * from Table2 where Last_Name Like '{Textbox12.Text}' ;


推荐阅读