VB的ADODC连接SQL2000,已经显示连接成功,怎么运行时显示对象变量和With块变量未设置啊 10
DimmsgAsStringDimSQLAsStringPrivateSubCmdOK_Click()DimrstAsADODB.RecordsetDimpassword...
Dim msg As String
Dim SQL As String
Private Sub CmdOK_Click()
Dim rst As ADODB.Recordset
Dim password As String
'判断密码是否正确
Sys_UserID = Trim(txtUserId.Text)
SQL = " select userID,password from 用户信息表 where userID='" & Sys_UserID & "'"
Set rst = SelectSQL(SQL, msg)
If rst.RecordCount > 0 Then '如果存在该用户
password = Trim(rst.Fields(1))
rst.Close
Else
If InsertUserInfo Then '如果输入的是读者号,且用户是第一次登陆
MsgBox ("欢迎读者使用,请你修改密码!")
Else
MsgBox ("用户ID或密码错误!")
End If
Exit Sub
End If
If password = Trim(txtPassword.Text) Then
Sys_LoginSucceeded = True
LibInfoSerSys.Show
Unload Me
Else
MsgBox ("密码错误!")
Sys_LoginSucceeded = False
End If
End Sub
Private Function InsertUserInfo() As Boolean
'如果输入的是读者号,且用户是第一次登陆,自动添加到用户列表
'返回true,如果不是读者号,返回false
Dim rst As ADODB.Recordset
SQL = " select * from 读者信息表 where readerID='" & Sys_UserID & "'"
Set rst = SelectSQL(SQL, msg)
If rst.RecordCount > 0 Then '如果存在该读者
SQL = "insert into" & _
"用户信息表(userID,userName,userType,password,competence,identificationU,addressU,telephoneU,emailU) "
SQL = SQL & " select readerID,readerName, userType,"
SQL = SQL & " '借书管理 : 还书管理 : 检索统计 :' as competence,identificationU,addressU,telephoneU,emailU "
SQL = SQL & " from 用户信息表 where readerID='" & Sys_UserID & "'"
Call ExecuteSQL(SQL, msg)
InsertUserInfo = True
Else
InsertUserInfo = False
End If
rst.Close
End Function
Private Sub cmdCancel_Click()
'设置全局变量为 false
'不提示失败的登录
Sys_LoginSucceeded = False
Unload Me
End Sub
Private Sub Form_Load()
'设置数据库连接字符串
ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=图书馆信息服务系统"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Sys_LoginSucceeded = False
Unload Me
End Sub
注:VB显示 If rst.RecordCount > 0 Then '如果存在该读者 该行有问题 不知道怎么处理啊 还有就是希望大家能告诉我如何VB连接SQL啊 展开
Dim SQL As String
Private Sub CmdOK_Click()
Dim rst As ADODB.Recordset
Dim password As String
'判断密码是否正确
Sys_UserID = Trim(txtUserId.Text)
SQL = " select userID,password from 用户信息表 where userID='" & Sys_UserID & "'"
Set rst = SelectSQL(SQL, msg)
If rst.RecordCount > 0 Then '如果存在该用户
password = Trim(rst.Fields(1))
rst.Close
Else
If InsertUserInfo Then '如果输入的是读者号,且用户是第一次登陆
MsgBox ("欢迎读者使用,请你修改密码!")
Else
MsgBox ("用户ID或密码错误!")
End If
Exit Sub
End If
If password = Trim(txtPassword.Text) Then
Sys_LoginSucceeded = True
LibInfoSerSys.Show
Unload Me
Else
MsgBox ("密码错误!")
Sys_LoginSucceeded = False
End If
End Sub
Private Function InsertUserInfo() As Boolean
'如果输入的是读者号,且用户是第一次登陆,自动添加到用户列表
'返回true,如果不是读者号,返回false
Dim rst As ADODB.Recordset
SQL = " select * from 读者信息表 where readerID='" & Sys_UserID & "'"
Set rst = SelectSQL(SQL, msg)
If rst.RecordCount > 0 Then '如果存在该读者
SQL = "insert into" & _
"用户信息表(userID,userName,userType,password,competence,identificationU,addressU,telephoneU,emailU) "
SQL = SQL & " select readerID,readerName, userType,"
SQL = SQL & " '借书管理 : 还书管理 : 检索统计 :' as competence,identificationU,addressU,telephoneU,emailU "
SQL = SQL & " from 用户信息表 where readerID='" & Sys_UserID & "'"
Call ExecuteSQL(SQL, msg)
InsertUserInfo = True
Else
InsertUserInfo = False
End If
rst.Close
End Function
Private Sub cmdCancel_Click()
'设置全局变量为 false
'不提示失败的登录
Sys_LoginSucceeded = False
Unload Me
End Sub
Private Sub Form_Load()
'设置数据库连接字符串
ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=图书馆信息服务系统"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Sys_LoginSucceeded = False
Unload Me
End Sub
注:VB显示 If rst.RecordCount > 0 Then '如果存在该读者 该行有问题 不知道怎么处理啊 还有就是希望大家能告诉我如何VB连接SQL啊 展开
展开全部
Private Sub CmdOK_Click()
Dim rst As ADODB.Recordset
改成
Private Sub CmdOK_Click()
Dim rst As New ADODB.Recordset
你的代码就是连接SQL 数据库,连接字符串可以从ADODC控件获取。
Dim cnn as New ADODB.Connection
cnn.connectionstring="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=图书馆信息服务系统"
cnn.open
if cnn.state=0 then '连接失败
Dim rst As ADODB.Recordset
改成
Private Sub CmdOK_Click()
Dim rst As New ADODB.Recordset
你的代码就是连接SQL 数据库,连接字符串可以从ADODC控件获取。
Dim cnn as New ADODB.Connection
cnn.connectionstring="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=图书馆信息服务系统"
cnn.open
if cnn.state=0 then '连接失败
展开全部
虽然很久没看vb了,但是我看了你的代码,从头到尾msg这个变量没有用到,而你的数据库处理中都有msg,希望你能好好看下书或者检查下代码。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Public Cn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public Cs As String
Private Sub Command1_Click()
Dim 用户名 As String * 18
Dim a As Integer
用户名 = Text1.Text
密码 = Text2.Text
Cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=chedui;Data Source=(local)"
Cn.CursorLocation = adUseClient
Cs = "select 用户名 from yonghu"
Rs.Open Cs, Cn, adOpenKeyset, adLockPessimistic
Do While Not Rs.EOF
If 用户名 = Rs("用户名") Then
a = 1
MsgBox "此用户已存在!请重新填写!", , "提示"
Text2.Text = ""
Text1.SetFocus
Exit Do
End If
Rs.MoveNext
Loop
Set Rs = Nothing
Set Cn = Nothing
If a <> 1 Then
If Text1.Text = "" Then
MsgBox "请输入用户名!", , "提示"
Text1.SetFocus
Else
If Text2.Text = "" Then
MsgBox "请输入密码!", , "提示"
Text2.SetFocus
Else
If MsgBox("确实要添加这条记录吗?", vbOKCancel, "系统提示") = vbOK Then
Cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=chedui;Data Source=(local)"
Cn.CursorLocation = adUseClient
Cs = "insert into yonghu values('" & 用户名 & " ','" & 密码 & " ')"
Rs.Open Cs, Cn, adOpenKeyset, adLockPessimistic
MsgBox "成功添加此记录!", , "系统提示"
Set Rs = Nothing
Set Cn = Nothing
Text1.Text = ""
Text2.Text = ""
End If
End If
End If
End If
Cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=chedui;Data Source=(local)"
Cn.CursorLocation = adUseClient
Cs = "select * from yonghu"
Rs.Open Cs, Cn, adOpenKeyset, adLockPessimistic
Set 用户信息.DataGrid1.DataSource = Rs
Set Rs = Nothing
Set Cn = Nothing
End Sub
这是一个与数据库连接添加用户的操作,你把里面的数据库名和表名改改就好了 ,无需用ado控件。用语句实现就好。
Public Rs As New ADODB.Recordset
Public Cs As String
Private Sub Command1_Click()
Dim 用户名 As String * 18
Dim a As Integer
用户名 = Text1.Text
密码 = Text2.Text
Cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=chedui;Data Source=(local)"
Cn.CursorLocation = adUseClient
Cs = "select 用户名 from yonghu"
Rs.Open Cs, Cn, adOpenKeyset, adLockPessimistic
Do While Not Rs.EOF
If 用户名 = Rs("用户名") Then
a = 1
MsgBox "此用户已存在!请重新填写!", , "提示"
Text2.Text = ""
Text1.SetFocus
Exit Do
End If
Rs.MoveNext
Loop
Set Rs = Nothing
Set Cn = Nothing
If a <> 1 Then
If Text1.Text = "" Then
MsgBox "请输入用户名!", , "提示"
Text1.SetFocus
Else
If Text2.Text = "" Then
MsgBox "请输入密码!", , "提示"
Text2.SetFocus
Else
If MsgBox("确实要添加这条记录吗?", vbOKCancel, "系统提示") = vbOK Then
Cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=chedui;Data Source=(local)"
Cn.CursorLocation = adUseClient
Cs = "insert into yonghu values('" & 用户名 & " ','" & 密码 & " ')"
Rs.Open Cs, Cn, adOpenKeyset, adLockPessimistic
MsgBox "成功添加此记录!", , "系统提示"
Set Rs = Nothing
Set Cn = Nothing
Text1.Text = ""
Text2.Text = ""
End If
End If
End If
End If
Cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=chedui;Data Source=(local)"
Cn.CursorLocation = adUseClient
Cs = "select * from yonghu"
Rs.Open Cs, Cn, adOpenKeyset, adLockPessimistic
Set 用户信息.DataGrid1.DataSource = Rs
Set Rs = Nothing
Set Cn = Nothing
End Sub
这是一个与数据库连接添加用户的操作,你把里面的数据库名和表名改改就好了 ,无需用ado控件。用语句实现就好。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
貌似VB中设置的值和SQL中的字符不匹配.....
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询