主题:输入字符串的格式不正确,怎么改正?
我用下面代码实现登陆界面, 学号和密码是数字还能用,可一变成字母例如学号=zm就提示这样的 错误:输入字符串的格式不正确。错误行是行 lngCount = cmd.ExecuteScalar(),提示说明:InvalidCastException: 从字符串“zm”到类型“Integer”的强制转换无效。请问怎么具体改正?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ConnString As String
Dim strSql As String
Dim Conn As New OleDbConnection
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
ConnString += Server.MapPath("22.mdb")
Conn.ConnectionString = ConnString
Conn.Open()
Dim cmd As New OleDbCommand
Dim lngCount As Integer
strSql = " select * from mima where 学号='" & txtUserName.Text & "'And 密码='" & Password.Text & "'"
cmd.Connection = Conn
cmd.CommandText = strSql
lngCount = cmd.ExecuteScalar()
If lngCount = "0" Then
Response.Write("<script languaage='javascript'>alert('对不起!用户名和密码不符,请重新输入!')</script>")
txtUserName.Text = ""
Password.Text = ""
Else
Response.Redirect("http://www.163.com")
End If
cmd.Dispose()
Conn.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ConnString As String
Dim strSql As String
Dim Conn As New OleDbConnection
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
ConnString += Server.MapPath("22.mdb")
Conn.ConnectionString = ConnString
Conn.Open()
Dim cmd As New OleDbCommand
Dim lngCount As Integer
strSql = " select * from mima where 学号='" & txtUserName.Text & "'And 密码='" & Password.Text & "'"
cmd.Connection = Conn
cmd.CommandText = strSql
lngCount = cmd.ExecuteScalar()
If lngCount = "0" Then
Response.Write("<script languaage='javascript'>alert('对不起!用户名和密码不符,请重新输入!')</script>")
txtUserName.Text = ""
Password.Text = ""
Else
Response.Redirect("http://www.163.com")
End If
cmd.Dispose()
Conn.Close()
End Sub