Imports System.Data
Imports System.Data.SqlClient
Partial Class main
Inherits System.Web.UI.Page
Dim objconn As SqlConnection
Dim objcmd As SqlCommand
Dim strconn As String
Protected Sub btnsubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsubmit.Click
If txtname.Text = "" Then
MsgBox("Insert Your Username")
ElseIf txtpass.Text <> txtcpass.Text Then
MsgBox("Password not Math")
ElseIf txtpass.Text = "" And txtcpass.Text = "" Then
MsgBox("Insert Password")
Else
Session("name") = txtname.Text
Session("pass") = txtpass.Text
Server.Transfer("addnewuser.aspx")
End If
End Sub
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
strconn = "Server=localhost; Uid=sa; PASSWORD=1234; database=test;"
objconn = New SqlConnection(strconn)
objconn.Open()
If objconn.State = ConnectionState.Open Then
lblbase.Text = "สามารถติดต่อฐานข้อมูลได้"
Else
lblbase.Text = "ไม่สามารถติดต่อฐานข้อมูลได้"
End If
objconn.Close()
objconn = Nothing
End Sub
End Class
Imports System.Data
Imports System.Data.SqlClient
Partial Class addnewuser
Inherits System.Web.UI.Page
Dim objconn As SqlConnection
Dim objcmd As SqlCommand
Dim strconn As String
Dim name As String
Dim pass As String
Dim strsql As String
Dim check As SqlDataReader
Dim num As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
btndel.Enabled = False
btnupdate.Enabled = False
strconn = "Server=localhsot; UID=sa; PASSWORD=1234; database=test;"
objconn = New SqlConnection(strconn)
objconn.Open()
If objconn.State = ConnectionState.Open Then
lblconn.Text = ("DATABSE Connection Success !")
Else
lblconn.Text = "DATABASE Connection Lose !"
End If
txtname.Text = Session("name")
txtpass.Text = Session("pass")
txtname.Enabled = False
txtpass.Enabled = False
End Sub
Protected Sub btninsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btninsert.Click
name = Session("name")
pass = Session("pass")
strsql = "insert into testtab1 (col1,col2) values ('" & name & "','" & pass & "') "
objcmd = New SqlCommand(strsql, objconn)
check = objcmd.ExecuteReader()
'While check.Read
' num = check("เพิ่มค่าเรียบร้อยแล้ว")
' MsgBox(num)
'End While
objconn.Close()
objconn = Nothing
Session("name") = name
btndel.Enabled = True
btnupdate.Enabled = True
btninsert.Enabled = False
End Sub
Protected Sub btndel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btndel.Click
Server.Transfer("deluser.aspx")
End Sub
Protected Sub btnupdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnupdate.Click
Server.Transfer("edituser.aspx")
End Sub
End Class
Imports System.Data
Imports System.Data.SqlClient
Partial Class login
Inherits System.Web.UI.Page
Dim objconn As SqlConnection
Dim objcmd As SqlCommand
Dim strConn As String
Dim username As String
Dim password As String
Dim strsql As String
Dim check As SqlDataReader
Dim num As Integer
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
strConn = "Server=localhost; Uid=sa; PASSWORD=1234; Database=test;"
objconn = New SqlConnection(strConn)
objconn.Open()
If objconn.State = ConnectionState.Open Then
Response.Write("Connection Pass !")
'txtUsername.Enabled = False
Else
Response.Write("Connection Lose !")
'txtPassword.Enabled = False
End If
End Sub
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
username = txtUsername.Text
password = txtPassword.Text
strsql = "select * from testtab1 where col1 = '" & username & "' and col2 = '" & password & "'"
objcmd = New SqlCommand(strsql, objconn)
'objcmd.ExecuteNonQuery()
'Response.Write(objcmd.ExecuteNonQuery())
check = objcmd.ExecuteReader()
'ล่างตรงนี้แหละครับที่มันเกิดปัญหา
While check.Read()
If (username = check("col1").ToString) And (password = check("col2").ToString) Then
MsgBox("Username And Password Right")
ElseIf (username <> check("col1").ToString) And (password <> check("col2").ToString) Then
MsgBox("Username And Password Fail")
End If
End While
check.Close()
objconn.Close()
End Sub
End Class