Imports System.Security.Cryptography
Imports System.Data
Imports System.Text
Imports System.Data.SqlClient
Public Class login
    Inherits System.Web.UI.Page
    Public objconn As New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("connstring"))
#Region " Web 窗体设计器生成的代码 "    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()    End Sub
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub#End Region    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
        If Not IsPostBack Then
            Session("a") = 0
        End If
    End Sub    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        If Session("a") <= 2 Then
            Dim strSQL As String = "SELECT * FROM newuser WHERE accountnum=@yUserid AND password=@Password"            Dim objCmd As New SqlCommand(strSQL, objconn)
            Dim paramUserid As SqlParameter
            paramUserid = New SqlParameter("@yUserid", SqlDbType.VarChar, 50)
            paramUserid.Value = TextBox1.Text
            objCmd.Parameters.Add(paramUserid)            '加密密码
            Dim md5Hasher As New MD5CryptoServiceProvider
            Dim hashedDataBytes As Byte()
            Dim encoder As New UTF8Encoding
            hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(TextBox2.Text))            Dim paramPwd As SqlParameter
            paramPwd = New SqlParameter("@Password", SqlDbType.Binary, 6)
            paramPwd.Value = hashedDataBytes
            objCmd.Parameters.Add(paramPwd)            objconn.Open()
            Dim iResults As Integer = objCmd.ExecuteScalar()
            objconn.Close()            If iResults = 1 Then
                Session("ying") = TextBox1.Text
                Response.Write("<SCRIPT LANGUAGE='javascript'>window.open('gnym.aspx',null,'height=480,width=640,top=150,left=200 ')</script>")
            ElseIf iResults = 0 Then
                Label1.Text = "密码或帐户不正确, 请重新输入"
                If Session("a") = 2 Then
                    Label1.Text = "错误!你已经输错了三次,请与管理员联系!"
                    Button1.Enabled = False
                    Exit Sub
                End If
                Session("a") += 1
            End If        End If
    End Sub
End Class郁闷!就是不知道那里有问题啊 !!!!!!!!类型“DBNull”到类型“Integer”的强制转换无效。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidCastException: 从类型“DBNull”到类型“Integer”的强制转换无效。源错误: 
行 61: 
行 62:             objconn.Open()
行 63:             Dim iResults As Integer = objCmd.ExecuteScalar()
行 64:             objconn.Close()
行 65: