【发布时间】:2018-05-01 08:39:40
【问题描述】:
我怎样才能摆脱:
System.InvalidCastException: '从字符串“类型”转换为类型 '整数' 无效。'"
上线:
Dim usertype = Reader.GetString("Type")
这是我的完整代码:
Private Sub OKbt1_Click(sender As Object, e As EventArgs) Handles OKbt1.Click
Call Connect() ' [ connection to module ]'
Dim Reader As SqlDataReader
Try
Dim command As New SqlCommand("select * from uinfo where password = '" & PASStb2.Text & "'", sqlConn)
Reader = command.ExecuteReader
Reader.Read()
Dim count As Integer = 0
While Reader.Read
count = count + 1
End While
If count = 1 Then
' ** MY ERROR **
Dim usertype = Reader.GetString("Type")
If usertype = "admin" Then
'MsgBox("username and password are correct")
MAIN_MENU.Show()
For a = 0 To 500
Next
Me.Hide()
sqlConn.Close()
sqlConn.Dispose()
ElseIf usertype = "user" Then
For a = 0 To 500
Next
Me.Hide()
'MsgBox("username and password are correct")
USERMENU.Show()
End If
ElseIf count > 1 Then
MsgBox("username and password are duplicate")
Else
MsgBox("username and password are not correct")
End If
sqlConn.Close()
Catch ex As SqlException
MsgBox(ex.Message)
Finally
sqlConn.Dispose()
End Try
End Sub
【问题讨论】:
-
Declare usertype as Dim usertype as String