2015-02-23 97 views
0

我有一個登錄頁面,我想收集用戶ID並使用會話來存儲它,所以我可以在重定向頁面上使用它。Vb.net登錄會話和Mysql查詢

登錄頁面:

Dim Query As String 
      Query = "select * from mdxmain.taffiliate where affID = '" & username.Text & "' and affPassword = '" & password.Text & "'" 
      COMMAND = New MySqlCommand(Query, MysqlConn) 
      Session("affID") = username.Text 
      HttpContext.Current.Session.Add("affID", userid) 

      READER = COMMAND.ExecuteReader 

      Dim count As Integer 
      count = 0 

      While READER.Read 
       count = count + 1 
      End While 

      If count = 1 Then 


       Response.Redirect("dashboard.aspx") 

      Else 
       Literal1.Text = "Invalid credentials" 
      End If 

      MysqlConn.Close() 

     Finally 

     End Try 
     MysqlConn.Dispose() 

和中有一個查詢頁面dashboard.aspx:

Dim c As New MySqlConnection("Server=localhost;Database=test;UID=test;PWD=test;") 
     c.Open() 
     Dim com As New MySqlCommand("SELECT COUNT(*) as c FROM toutcome WHERE AffID = 'MW0011' AND CompletedDate >= CURDATE();", c) 
     Dim myReader As MySqlDataReader = com.ExecuteReader(CommandBehavior.CloseConnection) 
     myReader.Read() 
     Label1.Text = myReader.Item(0).ToString() 

現在我想做的事是在用他的ID和我的客戶登錄想要將該ID複製到會話中,然後在上面的查詢中使用它(將MW0011替換爲會話ID),請幫助我。

回答

0

嘗試更換查詢WHERE AffID = 'MW0011'WHERE AffID = '" & CType(Session.Item("affID"), String) & "'

+0

我是否需要在新的頁面首先加載會議之前,我可以使用它? – Trifactor 2015-02-23 15:03:37

+0

工作很好!謝謝 – Trifactor 2015-02-23 15:09:04

+0

對不起昨晚睡了。不用謝。 :) – 2015-02-24 03:36:20