如何将asp变量传递给selectcommand?

时间:2010-04-08 18:37:48

标签: asp.net

我正在尝试将我正在检索的变量“PIN2”传递给asp SqlDataSource标记中的SelectCommand语句

  

<%

Dim PIN As String = Request.ServerVariables("LOGON_USER")
Dim PIN2 As String = Right(PIN, 6)
 %>

由于

1 个答案:

答案 0 :(得分:1)

如何在会话变量中将PIN重构为代码隐藏,然后在SQLDataSource标记中将其用作SessionParameter。

像这样:

<%@ Page Language="VB" %>   
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="vb" >

    Partial Class MyPending
        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            Dim PIN As String = Request.ServerVariables("LOGON_USER")
            Dim PIN2 As String = Right(PIN, 6)
            Session("PIN") = PIN2   
        End Sub            

    End Class
</script>

<asp:sqldatasource id="SqlDataSource1" runat="server" selectcommand="... WHERE USERPIN=@thepin">
  <selectparameters>
    <asp:sessionparameter sessionfield="PIN" type="String" name="thepin" />
  </selectparameters>
</asp:sqldatasource>