您好,我在 c Sharp 中的数据适配器出现错误。怎么修?
SqlCommand cmd = new SqlCommand("select * from View_1 where Words_Sh LIKE ' + @txbSearch + '%'", con);
cmd.Parameters.AddWithValue("@txbSearch", this.txbSearch.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd, con)
;
最佳答案
不要在参数占位符前添加单引号和加号
SqlCommand cmd = new SqlCommand("select * from View_1 " +
"where Words_Sh LIKE @txbSearch + '%'", con);
此外,我更喜欢将通配符直接连接到参数值内。
不过,不确定它是否有任何区别,只是偏好问题和查询字符串中更少的困惑。
SqlCommand cmd = new SqlCommand("select * from View_1 " +
"where Words_Sh LIKE @txbSearch", con);
cmd.Parameters.AddWithValue("@txbSearch", this.txbSearch.Text + "%");
关于c# - C Sharp 中的 SqlDataAdapter 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19747368/