| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3429 人关注过本帖
标题:初学者求助,vb编程问题!提示:“对象变量或with块变量未设置”
只看楼主 加入收藏
simpson
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:863
专家分:17
注 册:2006-11-16
收藏
得分:0 
以下是引用wangjiyu在2007-9-27 21:29:34的发言:

大家不要笑啊,我是初学的,呵呵。我会努力的!!!!希望能得到大家的帮助!

好 帮你啦

有没有 先。。。 Adodc1.ConnectionString 。。。。啊。。。。

建议1. 不要用 + 来连接字符串
2. 你只验证密码,不验证ID 啊?


全国最大的 Java专业电子书免费分享[url]http:///in.asp?id=xrmao[/url]
2007-09-27 22:53
mohan123
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2007-9-10
收藏
得分:0 

楼主,我把myuser类和mydb类发给你,你自己修改下就应该可以了:
myuser:
'1 UserName Varchar 40 用户名
'2 Pwd Varchar 40 密码
'3 RK TinyInt 用户类型
'(0 - 系统默认用户)
Public UserId As String
Public UserName As String
Public UPass As String
Public UPrav As String
Public UQx As String
'*********************************************
Public Sub Init()
UserId = ""
UserName = ""
UPrav = ""
UQx = ""
End Sub
'**********************************************
'删除UserInfo数据
Public Sub Delete(ByVal TmpUser As String)
If TmpUser = "1" Then
Kk = MsgBox("超级用户不准许删除", vbOKOnly, "警告")
Exit Sub
End If
Mydb.openDB
SqlStmt = "DELETE FROM UserInfo WHERE UserId='" _
+ Trim(TmpUser) + "'"
Dim Isexe As Boolean
Dim rsUser As ADODB.Recordset
Isexe = Mydb.exeSql(SqlStmt, rsUser, True)
Mydb.closeDB
End Sub
'**************************************************************
'获取UserInfo数据库信息
Public Function GetInfo(ByVal TmpUser As String) As Boolean
Dim TUserGd As Variant
If TmpUser = "" Then
Init
GetInfo = False
Exit Function
End If
UserName = TmpUser
'打开数据库
Mydb.openDB
SqlStmt = "SELECT * FROM UserInfo WHERE UserName='" _
+ Trim(TmpUser) + "'"
Dim Isexe As Boolean
Dim rsUser As ADODB.Recordset
Isexe = Mydb.exeSql(SqlStmt, rsUser, True)
'判断用户是否在数据库里,如果没有,则GetInfo=0
'否则读取用户信息和用户类型、权限
If rsUser.EOF Then

GetInfo = False
Mydb.closeDB
Exit Function
Else

UserId = rsUser.Fields("UserId")
UserName = rsUser.Fields("UserName")

If IsNull(rsUser.Fields("UPass")) = False Then
UPass = rsUser.Fields("UPass")
Else
UPass = ""
End If
UQx = rsUser.Fields("UQx")
UPrav = rsUser.Fields("UPrav")
GetInfo = True
Mydb.closeDB
End If
End Function
'**********************************************
Public Function GetNewId() As Long
Dim TmpId As Long
Mydb.openDB
SqlStmt = "Select UserId from UserInfo Order by UserId"
Dim Isexe As Boolean
Dim rsUser As ADODB.Recordset
Isexe = Mydb.exeSql(SqlStmt, rsUser, True)
i = 1
Do While rsUser.EOF = False
TmpId = rsUser.Fields("UserId")
If TmpId = i Then
i = i + 1
Else
GetNewId = i
Mydb.closeDB
Exit Function
End If
rsUser.MoveNext
Loop
Mydb.closeDB
GetNewId = i
End Function
'**************************************************************
'插入UserInfo信息
Public Sub Insert()
User_Id = GetNewId
Mydb.openDB
SqlStmt = "INSERT INTO UserInfo Values('" & Trim(str(User_Id)) & "'," _
+ "'" & Trim(UserName) & "','" & Trim(UPass) & "'," _
+ "'" & Trim(UPrav) & "'," _
+ "'" & Trim(UQx) & ")"
Dim Isexe As Boolean
Dim rsUser As ADODB.Recordset
Isexe = Mydb.exeSql(SqlStmt, rsUser, True)
Mydb.closeDB
End Sub
'**************************************************************
'更新UserInfo信息
Public Sub Update(ByVal TmpUser As String)
If Trim(TmpUser) = "Admin" Then
Kk = MsgBox("超级用户不准许修改", vbOKOnly, "警告")
Exit Sub
End If
Mydb.openDB
SqlStmt = "Update UserInfo Set UserName ='" + Trim(UserName) + "'" _
+ ",UPass='" + Trim(CStr(UPass)) + "'" _
+ ",UPrav='" + Trim(CStr(UPrav)) + "'" _
+ ",UQx='" + Trim(CStr(UQx)) + "'" _
+ " WHERE UserName='" + Trim(TmpUser) + "'"
Dim Isexe As Boolean
Dim rsUser As ADODB.Recordset
Isexe = Mydb.exeSql(SqlStmt, rsUser, True)
Mydb.closeDB
End Sub

mydb类:
Option Explicit
Private Const CONN_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
Public DB_PATH As String
'数据库连接
Public dbConn As New ADODB.Connection
'表明当前数据库的连接状态:False-未连接;True-已连接
Public dbStatus As Boolean
Public Function openDB() As Boolean
'DB_PATH = dbPath
'dbConn.Open CONN_STRING & DB_PATH
'MsgBox Err.Description
Dim connString As String
connString = "Provider=SQLOLEDB.1;User ID=sa;pwd=y69m10d17;Initial Catalog=Northwind;Data Source= hostlocal ;"
dbConn.Open "Provider=SQLOLEDB.1;User ID=sa;pwd=y69m10d17;Initial Catalog=Northwind;Data Source= hostlocal ;"
If err.Number <> 0 Then MsgBox err.Description: GoTo errHandler
'dbStatus = True
openDB = True
Exit Function
errHandler:
openDB = False
MsgBox ("数据库连接失败,请与系统管理员联系!")
End Function
Public Function closeDB() As Integer
dbConn.Close
'xxx
dbStatus = False
End Function
Public Function exeSql(sqlStr As String, queryResult As ADODB.Recordset, Optional enableWrite As Boolean = True) As Boolean
On Error GoTo errHandler:
Dim ret
Set queryResult = New ADODB.Recordset
If enableWrite Then
queryResult.Open sqlStr, dbConn, adOpenStatic, adLockOptimistic
Else
queryResult.Open sqlStr, dbConn, adOpenStatic, adLockReadOnly
End If
exeSql = True
Exit Function
errHandler:
MsgBox err.Description
exeSql = False
Exit Function
End Function


2007-09-28 08:49
快速回复:初学者求助,vb编程问题!提示:“对象变量或with块变量未设置”
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015918 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved