Imports System.Data.SqlClient Public Class FmLogin Dim FLG As Integer = 0 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.ShowDialog(Me) Me.Show() Me.Close() Else If FLG = 1 Then MsgBox("その入力方法は違法です。") Else MsgBox("ID,パスワードが一致しません") End If 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 COUNT(ユーザーID) FROM ユーザー情報" _ & " WHERE ユーザーID='" & id & "' AND パスワード='" & pass & "'" If 0 <= TextBox1.Text.IndexOf("'") Or 0 <= TextBox2.Text.IndexOf("'") Then FLG = 1 Else 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 End If 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
Public Class UserInfo Public Shared Property Id As String Public Shared Property UserName As String End Class