I'm trying to get my feet wet in ASP.net programming, as one of our companies applications is designed in it, and while I understand VB.net, ASP.net is a little strange to me. As a test, I've started working on a database driven web application that has a log in form. The log in form makes a call to an SQL database to see if the users name and PW exist in a table. If they do, it redirects them to the main form. SO far everything is working, but now I'd like to do a test by having the form write the current date/time back to the database to a field called "LastLogin" if their result was found.
What I have so far:
Partial Class Login
Inherits System.Web.UI.Page
Public Sub LogIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
Dim connStr As String = "Data Source=WHITE-DWARF;Initial Catalog=UserDatabase;Integrated Security=True"
Dim sqlconnet As Data.SqlClient.SqlConnection
Dim MyComm As Data.SqlClient.SqlCommand
sqlconnet = New Data.SqlClient.SqlConnection()
sqlconnet.ConnectionString = connStr
MyComm = New Data.SqlClient.SqlCommand("", sqlconnet)
MyComm.CommandType = Data.CommandType.Text
MyComm.CommandText = "SELECT * FROM Logins WHERE (UserName ='" & txtUserName.Text & "') AND (Password = '" & txtPassword.Text & "') "
sqlconnet.Open()
Dim result As Data.SqlClient.SqlDataReader = MyComm.ExecuteReader(Data.CommandBehavior.CloseConnection)
If result.HasRows = False Then
lblStatus.Text = "Username and/or Password does not exist!"
Else
Session("Username") = txtUserName.Text
Response.Redirect("success.aspx")
------> MyComm.CommandText = "UPDATE Logins SET LastLogin=" & Now & " WHERE (UserName ='" & txtUserName.Text & "') AND (Password = '" & txtPassword.Text & "')"
End If
result.Close()
End Sub
End Class
The text next to the "---->" is what I'm trying to have done back to the database, but not sure if I need to redeclare the whole SQL data connection again just to perform an UPDATE...is there an easier way than redeclaring everything?
It might be a generated image. What laptop has an 11th gen CPU and 40 series GPU??? The 2 GB of VRAM could be explained by virtualization, but not the mismatched parts.
I think you can use a credit card to donate
Here is the link https://www.neowin.net/donate/ (donate button) or by bank? (same page)
By coincidence our server guy @DaveLeggis at our server facility in the UK today replacing a router ($450+ cost) here's a pic of our rack:
Question
SirEvan
I'm trying to get my feet wet in ASP.net programming, as one of our companies applications is designed in it, and while I understand VB.net, ASP.net is a little strange to me. As a test, I've started working on a database driven web application that has a log in form. The log in form makes a call to an SQL database to see if the users name and PW exist in a table. If they do, it redirects them to the main form. SO far everything is working, but now I'd like to do a test by having the form write the current date/time back to the database to a field called "LastLogin" if their result was found.
What I have so far:
The text next to the "---->" is what I'm trying to have done back to the database, but not sure if I need to redeclare the whole SQL data connection again just to perform an UPDATE...is there an easier way than redeclaring everything?
Link to comment
https://www.neowin.net/forum/topic/940030-aspnet-update-sql-datetime-field-upon-successful-login/Share on other sites
3 answers to this question
Recommended Posts