1

選択した値から値を挿入しようとしています。フェッチされた行が 1 以上の場合、別のテーブルにデータを挿入します。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    '  Try
    con.Open()
    sql = "SELECT user_id, username, password FROM tbl_user WHERE username = '" & txt_user.Text & "' AND password= '" & txt_pass.Text & "' IS NOT NULL"
    cmd = New MySqlCommand(sql, con)
    dr = cmd.ExecuteReader
    While dr.Read
        txt_user.Text = dr("username")
        txt_pass.Text = dr("password")

        Main.Show()
        Me.Hide()
        ctr += 1

    End While

    If ctr = 0 Then
        MsgBox("Login Failed!")
        txt_user.Clear()
        txt_pass.Clear()
    Else
        sql = "INSERT INTO user_log(user_id, username, log_datetime)VALUES(" & dr(0) & ",'" & dr(1) & "','" & DateTime.Today & "')"
        cmd2 = New MySqlCommand(sql, con)
        cmd2.ExecuteNonQuery()
    End If
    dr.Close()
    cmd.Dispose()
    con.Close()
    ' Catch ex As Exception

    '  End Try

End Sub
4

0 に答える 0