Public Class FMBase Private Sub FMBase_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim Login As new FmLogin Me.Hide() Login.show End Sub End Class
Public Class FMBase Private Sub FMBase_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load If TextBox1.Text = 0 Then Me.Hide() Using f As New fmlogin f.ShowDialog() End Using Me.Close() Else Me.Show() End If End Sub End Class
Imports System.Data.SqlClient Public Class fmlogin Dim FLG As Integer = 0 Dim BBB As Boolean Const ConnectString As String = "Data Source=user;Initial Catalog=データベースシステム;Integrated Security=True" Public Class UserInfo Public Shared Property ID As String Public Shared Property UserName As String End Class 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 FMBase Main.TextBox1.Text = 1 Main.Show() 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 String 'IntegerからStringに変更。 Dim SQL As String = "SELECT ユーザー名 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.ToString(CMD.ExecuteScalar()) 'Convert.ToInt32からConvert.ToStringに変更 Catch ex As Exception MsgBox(ex.Message) End Try End Using End If Return BBB '「RESULT <> 0」にするとString "横横太郎 " から型 'Boolean' への変換は無効です。とエラー。エラー回避の為にBBBを使用 End Function