Imports System.Data.SqlClient Public Class Form1 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 TextBox1.Text.Trim = "" OrElse TextBox2.Text.Trim = "" Then MsgBox("IDとパスワードの両方を入力して下さい") Exit Sub End If If checkUser(TextBox1.Text.Trim, TextBox2.Text.Trim) Then Me.Hide() Dim frm As New Form2 frm.ShowDialog(Me) Me.Show() 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 count(ユーザID) FROM ユーザ情報" _ & " WHERE ユーザID='" & id & "' AND パスワード='" & pass & "'" 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 End Class