Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# c中的SqlDataAdapter错误_C#_C_Vb.net - Fatal编程技术网

C# c中的SqlDataAdapter错误

C# c中的SqlDataAdapter错误,c#,c,vb.net,C#,C,Vb.net,您好,我有一个错误的数据适配器在c夏普。如何修复 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)

您好,我有一个错误的数据适配器在c夏普。如何修复

 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 + "%");
例如:

string commandText=从视图中选择*,其中单词类似于@parameters
cmd.Parameters。AddWithValue@parameters,参数1

你的问题真的很难阅读和理解。例如,您得到了什么错误?vb.net和c与这个问题有什么关系?当你早些时候问了一个类似的问题时,我指出如果你给出了确切的错误信息,这将非常有帮助。情况仍然如此。说我有错误是没有用的。