Public Class UserInfo Public Class Userinfo Public Shared Property ID As String Public Shared Property UserName As String End Class End Class
Public Class FMBase Private Sub FMBase_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Using Login As New fmlogin If Login.ShowDialog(Me) <> Windows.Forms.DialogResult.OK Then Me.Close() End If End Using End Sub End Class
Imports System.Data.SqlClient Public Class fmlogin 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.Length = 0 Or TextBox2.Text.Length = 0 Then MessageBox.Show("パスワードとIDを両方記入して下さい", "エラー!") Else If CheckUser(TextBox1.Text.Trim, TextBox2.Text.Trim) Then Me.DialogResult = Windows.Forms.DialogResult.OK Me.Close() Else MessageBox.Show("入力した情報が間違っています。再度入力して下さい。", "エラー!") End If End If End Sub Private Function CheckUser(id As String, pass As String) As String Dim RESULT As String Dim SQL As String = "SELECT ユーザー名 FROM ユーザー情報 WHERE ユーザーID='" & Replace(id, "'", "''") & "' AND パスワード='" & Replace(pass, "'", "''") & "'" Using conn As New SqlConnection(ConnectString) Dim CMD As New SqlCommand(SQL, conn) Try conn.Open() RESULT = Convert.ToString(CMD.ExecuteScalar()) With UserInfo .ID = id .UserName = RESULT '.ID,.UserNameに「Login.UserInfoのメンバーではありませんと青い波線でエラー表示 End With Catch ex As Exception MsgBox(ex.Message) End Try End Using Return RESULT IsNot Nothing End Function Private Sub btnQuit_Click(sender As System.Object, e As System.EventArgs) Handles btnQuit.Click Me.Close() End Sub End Class