Hello
I am a complete beginner to Visual Studio (Web) 2013.
I am trying to devise a 'new user registration form' form a Web page and in VS I have included three fields, username, password, and email address, in my Register.aspx page.
I now wish to include the following database script in that same aspx page:
providerName="System.Data.OleDb"/>
Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
conn.Open()
Dim sql As String = "INSERT INTO userlist (username,password, strEmail) VALUES (@username,@password, @strEmail)"
Dim conn As OleDbConnection = New OleDbConnection
cmd.Parameters.AddWithValue("@username", txtusername.Text)
cmd.Parameters.AddWithValue("@password", txtpassword.Text)
cmd.Parameters.AddWithValue("@strEmail", txtstrEmail.Text)
cmd.ExecuteNonQuery()
conn.Close()
cmd.Dispose()
conn.Dispose()
I wonder if someone would mind casting their eye over that script - I am not too sure about the syntax or order - and, perhaps, indicate to me if that should be part of an event such as 'when this submit button is clicked, insert the form data into the database'.
This is what the button looks like on my aspx page:
But I am not sure at all about how to 'marry' the database code above with the 'OnClick' event.
I would appreciate any assistance.
Thank you.
Blue
Protected Sub CreateUser_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As OleDbConnection = New OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings("usersConnectionString").ConnectionString)
Dim sql As String = "INSERT INTO userlist (username,password, strEmail) VALUES (@username,@password, @strEmail)"
Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
conn.Open()
cmd.Parameters.AddWithValue("@username", txtusername.Text)
cmd.Parameters.AddWithValue("@password", txtpassword.Text)
cmd.Parameters.AddWithValue("@strEmail", txtstrEmail.Text)
conn.Close()
cmd.Dispose()
conn.Dispose()
End Sub
WOW!
Thank you oned_gk!
I will go through your script and try to understand the logic and your thinking behind it - as well as use it, of course
. It
looks just what I need!I'm very grateful!
Blueie
沒有留言:
張貼留言