• 在c#中使用sql语句对数据库的表中数据进行模糊查询,当使用数字进行模
  • java

最近在学c#数据模型那一块,学习过程中使用sql语句对数据库的表中数据进行模糊查询,当使用数字进行模糊查询时能正常显示,但是汉字就不行,请大佬帮忙看下问题出在哪里,具体情况见下图

代码如下:

string connectionstr =
           ConfigurationManager.ConnectionStrings["Dbconnection"].ConnectionString;
           SqlConnection con = new SqlConnection(connectionstr);
           con.Open();
           if (comboBox1.SelectedIndex == 0)
           {
               SqlDataAdapter sda = new SqlDataAdapter("SELECT 学号,姓名,语文,数学,英语,政治,历史,地理 FROM score WHERE 学号 LIKE '%"+textBox10.Text+"%'", con);
               DataSet ds = new DataSet();
               sda.Fill(ds, "score");
               dataGridView4.DataSource = ds.Tables["score"];
           }
           if (comboBox1.SelectedIndex == 1)
           {
               SqlDataAdapter sda = new SqlDataAdapter("SELECT 学号,姓名,语文,数学,英语,政治,历史,地理 FROM score WHERE 姓名 LIKE '%"+textBox10.Text+"%'", con);
               DataSet ds = new DataSet();
               sda.Fill(ds, "score");
               dataGridView4.DataSource = ds.Tables["score"];
           }
           con.Close();


  • Caroline    2020-06-12 09:54:07
  • 阅读 939    收藏 0    回答 1
  • 邀请
  • 收藏
  • 分享
发送
登录 后发表评论
  • 51testing软件测试圈微信