选择带参数的语句 [英] Select Statement with Parameters
问题描述
以下代码不返回任何结果。从
问号中删除引号会产生以下错误:''''附近的语法不正确。
用William替换问号会产生结果。请
帮助!!
://比尔
<%@ Page language =" VB" ;%>
<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN"
" http:// www。 w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< HTML>
< script language =" VB" ; runat =" server">
Sub Page_Load(sender As Object,e As EventArgs)
Dim login_user As String
login_user = Request .ServerVariables(" LOGON_USER")
Session.Add(" User_ID",login_user)
Response.Write(" SCRIPT部分的会话ID是:< ; B>"&
会话(" User_ID")&"< / B>。继续......")
结束Sub
< / script>
< body>
< form id =" Form1"方法= QUOT;交" runat =" server">
< P>显示我的订单:< / P>
< asp:SqlDataSource
id =" OdbcDataSource1"
runat =" server"
ProviderName =" System.Data.SqlClient"
ConnectionString =" Data Source = XXX; Initial
Catalog = Employee; Persist Security Info = True; User ID = YYY; Password = ZZZ"
SelectCommand =" SELECT EmpFirstname,EmpMiddlename,
EmpLastName
来自员工
WHERE EmpFirstname =''?''
ORDER BY EmpLastName ;" />
< SelectParameters>
< asp:SessionParameter
Name =" empid"
SessionField =" User_ID"
DefaultValue =" William" />
< / SelectParameters>
< / asp:SqlDataSource>
< p>
< asp:GridView
id =" GridView1"
runat =" server"
DataSourceID =" OdbcDataSource1" />
< / p>
< / form>
< / body>
< / HTML>
The following code returns no results. Removing the quotes from the
question mark yields the following error: Incorrect syntax near ''?''.
Replacing the question mark with William does give results. Please
help!!
://Bill
<%@ Page language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim login_user As String
login_user = Request.ServerVariables("LOGON_USER")
Session.Add("User_ID", login_user)
Response.Write("Session ID from the SCRIPT section is: <B>" &
Session("User_ID") & "</B>. Moving on....")
End Sub
</script>
<body>
<form id="Form1" method="post" runat="server">
<P>Show My Orders:</P>
<asp:SqlDataSource
id="OdbcDataSource1"
runat="server"
ProviderName="System.Data.SqlClient"
ConnectionString="Data Source=XXX;Initial
Catalog=Employee;Persist Security Info=True;User ID=YYY;Password=ZZZ"
SelectCommand="SELECT EmpFirstname, EmpMiddlename,
EmpLastName
FROM Employee
WHERE EmpFirstname = ''?''
ORDER BY EmpLastName;"/>
<SelectParameters>
<asp:SessionParameter
Name="empid"
SessionField="User_ID"
DefaultValue="William" />
</SelectParameters>
</asp:SqlDataSource>
<p>
<asp:GridView
id="GridView1"
runat="server"
DataSourceID="OdbcDataSource1" />
</p>
</form>
</body>
</HTML>
推荐答案
2006年6月15日11:04:03 -0700, wh ***** @ gmail.com 写道:
On 15 Jun 2006 11:04:03 -0700, wh*****@gmail.com wrote:
以下代码不返回任何结果。从
问号中删除引号会产生以下错误:'''''附近的语法不正确。
用William替换问号会产生结果。请
帮助!!
The following code returns no results. Removing the quotes from the
question mark yields the following error: Incorrect syntax near ''?''.
Replacing the question mark with William does give results. Please
help!!
你不能用吗?句法。使用命名参数。
WHERE EmpFirstname =''@ empid''
You can''t use the ? syntax. Use named parameters.
WHERE EmpFirstname = ''@empid''
Erik Funkenbusch写道:
Erik Funkenbusch wrote:
2006年6月15日11:04:03 -0700, wh*****@gmail.com 写道:
On 15 Jun 2006 11:04:03 -0700, wh*****@gmail.com wrote:
以下代码不返回任何结果。从
问号中删除引号会产生以下错误:'''''附近的语法不正确。
用William替换问号会产生结果。请
帮助!!
The following code returns no results. Removing the quotes from the
question mark yields the following error: Incorrect syntax near ''?''.
Replacing the question mark with William does give results. Please
help!!
你不能用吗?句法。使用命名参数。
WHERE EmpFirstname =''@ empid''
You can''t use the ? syntax. Use named parameters.
WHERE EmpFirstname = ''@empid''
自动添加撇号。
>
WHERE EmpFirstname = @empid
The apostrophes is added automatically.
WHERE EmpFirstname = @empid
EmpFirstname = @empid生成SQL错误:必须声明
变量... ..
G?ran Andersson写道:
EmpFirstname = @empid generates a SQL error: "Must declare
variable....."
G?ran Andersson wrote:
Erik Funkenbusch写道:
Erik Funkenbusch wrote:
2006年6月15日11:04: 03 -0700, wh*****@gmail.com 写道:
On 15 Jun 2006 11:04:03 -0700, wh*****@gmail.com wrote:
以下代码不返回任何结果。从
问号中删除引号会产生以下错误:'''''附近的语法不正确。
用William替换问号会产生结果。请
帮助!!
The following code returns no results. Removing the quotes from the
question mark yields the following error: Incorrect syntax near ''?''.
Replacing the question mark with William does give results. Please
help!!
你不能用吗?句法。使用命名参数。
WHERE EmpFirstname =''@ empid''
You can''t use the ? syntax. Use named parameters.
WHERE EmpFirstname = ''@empid''
撇号会自动添加。
WHERE EmpFirstname = @empid
The apostrophes is added automatically.
WHERE EmpFirstname = @empid
这篇关于选择带参数的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!