Protected Sub Login_Click(sender As Object, e As EventArgs) Handles Login.Click
Dim objConn As New MySqlConnection
Dim objCmd As New MySqlCommand
Dim strConnString, strSQL As String
strConnString = "Server=localhost;User Id=root; Password=1234; Database=feederphone; Pooling=false"
objConn.ConnectionString = strConnString
objConn.Open()
Dim intNumRows As Integer
strSQL = "SELECT COUNT(*) FROM login WHERE KeyID = '" & Me.USERlog.Text & "' AND Password = '" & Me.Passlog.Text & "' "
objCmd = New MySqlCommand(strSQL, objConn)
intNumRows = objCmd.ExecuteScalar
If intNumRows > 0 Then
Session("strUser") = Me.USERlog.Text()
Response.Redirect("index.aspx")
Else
End If
objConn.Close()
objConn = Nothing
End Sub
โดยอยากส่งค่าใน USERlog.text ไปใช้ในค่า KeyID
ในหน้า
Masterpage.master
Code (VB.NET)
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim objConn As New MySqlConnection
Dim objCmd As New MySqlCommand
Dim strConnString, strSQL As String
strConnString = "Server=localhost;User Id=root; Password=1234; Database=feederphone; Pooling=false"
strSQL = "INSERT INTO feeder_sched (hour_1,min_1,hour_2,min_2,hour_3,min_3,weight_1,weight_2,weight_3,KeyID) " & _
" VALUES " & _
" ('" & Me.Hour1.Text & "','" & Me.Min1.Text & "', " & _
" '" & Me.Hour2.Text & "','" & Me.Min2.Text & "','" & Me.Hour3.Text & "','" & Me.Min3.Text & "','" & Me.weight1.Text & "','" & Me.weight2.Text & "','" & Me.weight3.Text & "','" & & "')"
objConn.ConnectionString = strConnString
objConn.Open()
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
Try
objCmd.ExecuteNonQuery()
MsgBox("Saved")
Catch ex As Exception
MsgBox("Error")
End Try
objConn.Close()
objConn = Nothing
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim objConn As New MySqlConnection
Dim objCmd As New MySqlCommand
Dim strConnString, strSQL As String
strConnString = "Server=localhost;User Id=root; Password=1234; Database=feederphone; Pooling=false"
strSQL = "UPDATE feederphone.feeder_sched SET hour_1='" & Hour1.Text & "',min_1='" & Min1.Text & "',hour_2='" & Hour2.Text & "',min_2='" & Min2.Text & "',hour_3='" & Hour3.Text & "',min_3='" & Min3.Text & "',weight_1='" & weight1.Text & "',weight_2='" & weight2.Text & "',weight_3='" & weight3.Text & "',KeyID='" & IDM.Text & "' WHERE KeyID = '" & IDM.Text & "'"
objConn.ConnectionString = strConnString
objConn.Open()
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
Try
objCmd.ExecuteNonQuery()
MsgBox("Saved")
Catch ex As Exception
MsgBox("Error")
End Try
objConn.Close()
objConn = Nothing
End Sub