c# - 如何创建搜索按钮或如何使用文本框对数据库进行行过滤?
问题描述
我使用了 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();
将出现一条错误消息,指出
“未找到列”或“缺少操作数”
解决方案
Textbox12.Text,并使用 Like 代替 =
更具可读性: $"select * from Table2 where Last_Name Like '{Textbox12.Text}' ;
推荐阅读
- vim - 如何在vim中使用搜索和替换将一个字符替换为多个字符
- wpf - 无法在 WPF 列表框中滚动
- pyspark - Pyspark 使用 datastax 连接器在 Cassandra 中插入时间
- google-cloud-platform - Google Composer - Airflow:我的任务没有安排
- json - FlatList 在获取 json 后接收未定义的值
- azure - Azure 逻辑应用程序的身份问题
- javascript - 编辑 Highcharts Legend 上的点击事件
- winforms - Direct2D 与 GDI+ 渲染目标混合透明为黑色
- command-line - 如何使用命令行将 TFS 代码下载到本地工作区
- java - 如何创建一个文本文件,然后在其中放入一个字符串?