求指点:在类中定义变量后,引用时却提示未声明变量
本帖最后由 qwayy 于 2012-09-01 15:24:55 编辑 我在看 vb.net2005数据库项目案例导航 时跟着做的练习,却提示未声明的变量,如下代码,请高人指点,谢谢
Imports System.Data.SqlClient
Public Class EditData
Shared Function Search(ByVal ConnStr As String, ByVal strSQL As String) As DataTable
'创建SqlConnection实例
Dim conn As SqlConnection = New SqlConnection(ConnStr)
'创建SQL命令
Dim myCommand As SqlCommand = New SqlCommand(strSQL, conn)
'打开数据库连接
conn.Open()
'设置适配器
Dim adapter As New SqlDataAdapter
adapter.TableMappings.Add("Table", "TEMP")
adapter.SelectCommand = myCommand
'填充数据集
Dim ObjectdaDataSet As New DataSet()
adapter.Fill(ObjectdaDataSet)
'关闭数据库连接
conn.Close()
'返回查询的表
Return ObjectdaDataSet.Tables("TEMP")
End Function
end class
Public Class DBuser
Public Function LoginConfirm() As Boolean
'设置SQL查询语句
Dim SQLString As String = "SELECT * FORM tbUSER WHERE 用户名='" & _UserName & "' and 密码='" & DBuser.Encrypt(_Password) & "'"
'得到记录用户信息的表
Dim UserTable As DataTable = EditData.Search(ConnStr, SQLString)'#############这里的ConnStr提示未声明变量
'判断用户名和密码是否正确
If UserTable.Rows.Count = 0 Then
MsgBox("用户名或密码输入不正确,请重试", MsgBoxStyle.Exclamation, "信息框")
Return False
Else
'返回用户的信息
_UserNo = UserTable.Rows(0)("用户编号")
_EMail = UserTable.Rows(0)("电子邮箱")
_Phone = UserTable.Rows(0)("联系电话")
_Address = UserTable.Rows(0)("家庭住址")
_Power = UserTable.Rows(0)("权限")
Return True
End If
End Function
End Class