Imports System.Data.SqlClient Public Class FmLogin Public Shared Property UserID As String Public Shared Property UserName As String Const ConnectString As String = "Data Source=user;Initial Catalog=データベースシステム;Integrated Security=True" Private Sub btnGo_Click(sender As System.Object, e As System.EventArgs) Handles btnGo.Click If CheckUser(TextBox1.Text.Trim, TextBox2.Text.Trim) Then Me.Hide() Dim Main As New fmmain Main.Label1.Text = FmLogin.UserName Main.ShowDialog(Me) Me.Show() Me.Close() Else MsgBox("ID,パスワードが一致しません") End If End Sub Private Function CheckUser(id As String, pass As String) As Boolean Dim RESULT As String = 0 Dim SQL As String = "SELECT ユーザー名 FROM T確定ユーザー情報" _ & " WHERE ユーザーID='" & id & "' AND パスワード='" & pass & "'" If RESULT IsNot Nothing Then FmLogin.UserID = id FmLogin.UserName = RESULT End If Using conn As New SqlConnection(ConnectString) Dim CMD As New SqlCommand(SQL, conn) Try conn.Open() RESULT = Convert.ToInt32(CMD.ExecuteScalar()) Catch ex As Exception MsgBox(ex.Message) End Try End Using Return RESULT <> 0 End Function Private Sub btnQuit_Click(sender As System.Object, e As System.EventArgs) Handles btnQuit.Click Me.Close() End Sub End Class
Imports System.Data.SqlClient Public Class FmLogin Public Shared Property UserID As String Public Shared Property UserName As String Const ConnectString As String = "Data Source=user;Initial Catalog=データベースシステム;Integrated Security=True" Private Sub btnGo_Click(sender As System.Object, e As System.EventArgs) Handles btnGo.Click If CheckUser(TextBox1.Text.Trim, TextBox2.Text.Trim) Then Me.Hide() Dim Main As New fmmain Main.Label1.Text = FmLogin.UserName Main.ShowDialog(Me) Me.Show() Me.Close() Else MsgBox("ID,パスワードが一致しません") End If End Sub Private Function CheckUser(id As String, pass As String) As Boolean Dim RESULT As Integer = 0 Dim SQL As String = "SELECT ユーザー名 FROM T確定ユーザー情報" _ & " WHERE ユーザーID='" & id & "' AND パスワード='" & pass & "'" If ※RESULT※ IsNot Nothing Then FmLogin.UserID = id FmLogin.UserName = RESULT End If Using conn As New SqlConnection(ConnectString) Dim CMD As New SqlCommand(SQL, conn) Try conn.Open() RESULT = Convert.ToInt32(CMD.ExecuteScalar()) Catch ex As Exception MsgBox(ex.Message) End Try End Using Return RESULT <> 0 End Function Private Sub btnQuit_Click(sender As System.Object, e As System.EventArgs) Handles btnQuit.Click Me.Close() End Sub End Class