开发者

How do I pass an asp variable to a selectcommand?

开发者 https://www.devze.com 2022-12-25 22:27 出处:网络
I am trying to pass a variable \"PIN2\" that I am retrieving like below to开发者_StackOverflow aSelectCommand statement in a asp SqlDataSource tag

I am trying to pass a variable "PIN2" that I am retrieving like below to开发者_StackOverflow a SelectCommand statement in a asp SqlDataSource tag

<%

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

Thanks


How about refactoring your PIN to your code-behind in a Session Variable and then using it inside your SQLDataSource tag as a SessionParameter.

Like this:

<%@ 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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号