Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.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# 有人能帮我了解select查询的语法吗?_C#_Sql - Fatal编程技术网

C# 有人能帮我了解select查询的语法吗?

C# 有人能帮我了解select查询的语法吗?,c#,sql,C#,Sql,我在做什么 string sql = "select * from publisher where title like "'"+tbproperty.text+"; 但它不起作用 关于..更正 string sql = "select * from publisher where title like '" + tbproperty.text + "'"; 更正 string sql = "select * from publisher where title like '" + tbpr

我在做什么

string sql = "select * from publisher where title like "'"+tbproperty.text+";
但它不起作用

关于..

更正

string sql = "select * from publisher where title like '" + tbproperty.text + "'";
更正

string sql = "select * from publisher where title like '" + tbproperty.text + "'";
使用:

如果需要向参数添加更多内容,请执行以下操作(例如:输出参数):

这意味着您不需要构建字符串本身并停止SQL注入。

使用:

如果需要向参数添加更多内容,请执行以下操作(例如:输出参数):


这意味着您不需要构建字符串本身并停止SQL注入。

类似,如果希望开始/结束匹配,则需要一些通配符,例如
'%'
,我假设用户没有添加这些通配符;但是-重要的:。曾经你想要的是:

sql = "select * from publisher where title like @arg";
cmd.Parameters.AddWithValue("@arg", "%" + tbproperty.text + "%");
@arg
定义为参数,其值类似于:

sql = "select * from publisher where title like @arg";
cmd.Parameters.AddWithValue("@arg", "%" + tbproperty.text + "%");

使用类似于
,如果希望开始/结束匹配,则需要一些通配符,例如
“%”
,我假设用户没有添加这些通配符;但是-重要的:。曾经你想要的是:

sql = "select * from publisher where title like @arg";
cmd.Parameters.AddWithValue("@arg", "%" + tbproperty.text + "%");
@arg
定义为参数,其值类似于:

sql = "select * from publisher where title like @arg";
cmd.Parameters.AddWithValue("@arg", "%" + tbproperty.text + "%");

发生了什么-它是如何失败的?对于信息,你在文字后面缺少一个结束引用,但正如大多数答案和评论告诉你的那样;使用一个参数。会发生什么-它是如何失败的?对于信息,您在文字后面缺少一个结束引号,但正如大多数答案和注释所告诉您的;使用参数。嘿,听着。。我在我的类中有我的函数,但tbproperty没有显示在我的类中??我该怎么做???@Azka-只有你知道
tbproperty
存在的地方;如果您单独对UI进行数据访问(您应该这样做),那么您必须将所需的标题作为参数传递给您的方法。我的类publisher中有我的search publisher函数,它是:public int searchpublisher(){SqlCommand cmd=new SqlCommand(“select*from publisher where title like@title”);cmd.Parameters.AddWithValue(“@title”,但在对象值中,tbproperty在intellisence..}中不存在。您可以在Publisher类中修改metod,如下所示:public int searchpublisher(string title){SqlCommand cmd=new SqlCommand(“select*from Publisher where title like@title”);cmd.Parameters.AddWithValue(“@title”,title);}然后从UI中的适当位置(即您可以访问文本框的位置)调用该方法,并按如下方式调用:int publisher=searchpublisher(tbproperty.Text);嘿,听着..我在我的类中有我的函数,但tbproperty在我的类中没有显示..?我该怎么做?@Azka-只有你知道
tbproperty
存在的位置;如果你单独对UI进行数据访问(你应该这样做)然后您必须将所需的标题作为参数传递给您的方法。我的类publisher中有我的search publisher函数,它是:public int searchpublisher(){SqlCommand cmd=new SqlCommand(“select*from publisher where title like@title”);cmd.Parameters.AddWithValue(@title,但在对象值中,tbproperty在intellisence中不存在。}您可以在Publisher类中修改metod如下:public int searchpublisher(字符串标题){SqlCommand cmd=new SqlCommand(“select*from Publisher where title like@title”);cmd.Parameters.AddWithValue(@title),title);}然后从UI中的适当位置(即您可以访问文本框的位置)调用该方法,并按如下方式调用:int publisher=searchpublisher(tbproperty.Text);+1希望我可以+10000您的答案!!始终(没有例外)使用参数化查询。+1希望我可以+10000您的答案!!始终(无例外)使用参数化查询。