My database consist of a table called Credential with 4 fields Username, Password, LoginFlag and SessionID
SELECT STATEMENT seems fine but UPDATE is NOT working.
I am pretty sure my code is correct. I follow the code from asp.net workbook by Heng Ngee Mok.
Imports System.Data.OleDb
Public Class Authentication
Inherits System.Web.UI.Page
Dim cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\wwwroot\MMORPGapi\MMORPG.mdb")
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim asd As String = HttpContext.Current.Request("username")
testLabel.Text = asd
Dim username As String = "jianda"
Dim pwd As String = "jiandapass"
Dim SID As String = "tester"
UsernameAndPwdAreValid(username, pwd, SID)
Response.Write("Hello JD!")
End Sub
Private Sub UsernameAndPwdAreValid(ByVal username As String, ByVal pwd As String, ByVal SID As String)
Dim sqlStr As String = "SELECT COUNT(*) AS NUMBEROFROWS FROM Credential WHERE [Username] = '" + username + "' AND [Password] = '" + pwd + "'"
Dim cmd As New OleDbCommand(sqlStr, cnn)
Dim dataReader As OleDbDataReader
Trace.Write(sqlStr)
Try
cnn.Open()
dataReader = cmd.ExecuteReader()
Dim counter As Integer
Do While dataReader.Read
counter = Convert.ToInt16(dataReader("NUMBEROFROWS"))
Loop
If counter = 1 Then
dataReader.Close()
Dim online As String = "online"
sqlStr = "UPDATE Credential SET [LoginFlag]='" + online + "', [SessionID]='" + SID + "' WHERE [Username]='" + username + "'"
Trace.Write(sqlStr)
cmd.ExecuteNonQuery()
End If
Catch ex As Exception
Finally
If Not cnn Is Nothing Then
cnn.Close()
cnn.Dispose()
End If
End Try
End Sub
End Class
None
0 Points
38 Posts
Re: asp.net .vb UPDATE ms access database not working
Jan 13, 2014 05:31 AM|I0ri|LINK
Thanks for helping Terry! Below is the code!
My database consist of a table called Credential with 4 fields Username, Password, LoginFlag and SessionID
SELECT STATEMENT seems fine but UPDATE is NOT working.
I am pretty sure my code is correct. I follow the code from asp.net workbook by Heng Ngee Mok.