|
First, reference the code Imports System.Data.SqlClient at the top of the Default.aspx.vb page.
Then give you an example to understand.
Dim con As New SqlConnection ("server = .; database = jie; uid = sa")
// server =. It means the machine is connected, the database name is added with the database name you want to connect, the user name and password are your own.
Dim cmd As New SqlCommand ("select Uid from user table where user name = '"&TextBox1.Text&"' and user password = '"&TextBox2.Text&"'", con)
Dim dr As SqlDataReader
con.Open ()
dr = cmd.ExecuteReader
If dr.Read Then
Response.Redirect ("WebForm1.aspx")
Else
Response.Write ("<script> alert ('The username or password is wrong') </ script>")
End If
dr.Close ()
con.Close () |
|