本文介绍了在SQL中使用like和参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从表中选择数据,如果它们的名称像文本框tex一样,为此我编写此代码
i want to select datas from table if they name like a text box tex , for this i write this code
string str = "Data Source=C:\\Documents and Settings\\almas\\Desktop\\BazarKhodro\\khodro.sdf"; Qconnection.ConnectionString = str; Qcommand.Connection = Qconnection; string commandText = "select id,name,lname,phone,mobile,address from moshtari where name like '% @name %' and lname like '% @lname %'"; Qcommand.Parameters.AddWithValue("@name", textBox3.Text); Qcommand.Parameters.AddWithValue("@lname", textBox4.Text); Qcommand.CommandText = commandText; Qcommand.CommandType = CommandType.Text; SqlCeDataAdapter a = new SqlCeDataAdapter(); a.SelectCommand = Qcommand; a.Fill(k); Qconnection.Open(); Qconnection.Close(); return k;但也无法正常工作,我也用sql编写查询,没有错误,但不显示结果,请帮我
but dont work correct also i write the query in sql and dont have error but dont show the result pleas help me
推荐答案删除%和@lname 之间的空格后,您可以尝试吗? I.E Hi Can you try after removing the blank space between % and @lname ? I.E string commandText = "select id,name,lname,phone,mobile,address from moshtari where name like ''% @name %'' and lname like ''%@lname%''";
您可以尝试: You can try: select id,name,lname,phone,mobile,address from moshtari where name like ''%'' + @name + '' %'' and lname like ''% '' + @lname + ''%''
更多推荐
在SQL中使用like和参数
发布评论