Option Explicit
Public m_Con As ADODB.Connection
Public m_Rs As ADODB.RecordsetPublic Sub main()
Dim ConnStr As String
Set m_Con = CreateObject("ADODB.Connection")
ConnStr = "driver={Microsoft Access Driver (*.mdb)};dbq=" & App.Path & "\school.mdb"
m_Con.Open ConnStr
Load frmLogin
frmLogin.Show
End Sub
Option Explicit
Private Sub cmdCancel_Click()
End
End SubPrivate Sub cmdOK_Click()
Dim sql As String
sql = "select * from user where username=" & "'" & txtUserName & "'" & " and password=" & "'" & txtPassword & "'"
Set m_Rs = New ADODB.Recordset
m_Rs.Open sql, m_Con, adOpenDynamic, adLockOptimistic
If Not m_Rs.EOF Then
Unload Me
Load MDIForm1
MDIForm1.Show
Set m_Rs = Nothing
Else
MsgBox "Invalid Password, try again!", , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub
Public m_Con As ADODB.Connection
Public m_Rs As ADODB.RecordsetPublic Sub main()
Dim ConnStr As String
Set m_Con = CreateObject("ADODB.Connection")
ConnStr = "driver={Microsoft Access Driver (*.mdb)};dbq=" & App.Path & "\school.mdb"
m_Con.Open ConnStr
Load frmLogin
frmLogin.Show
End Sub
Option Explicit
Private Sub cmdCancel_Click()
End
End SubPrivate Sub cmdOK_Click()
Dim sql As String
sql = "select * from user where username=" & "'" & txtUserName & "'" & " and password=" & "'" & txtPassword & "'"
Set m_Rs = New ADODB.Recordset
m_Rs.Open sql, m_Con, adOpenDynamic, adLockOptimistic
If Not m_Rs.EOF Then
Unload Me
Load MDIForm1
MDIForm1.Show
Set m_Rs = Nothing
Else
MsgBox "Invalid Password, try again!", , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub
解决方案 »
- 如何用CommandButton按钮控制listbox的滚动条滚动?
- Can总线数据采集.我使用了Can转串口设备.怎么确定每一帧的界线啊
- vba sql inset 出错!!
- 一个关于运算类型的问题?
- Access数据库操作
- Excel_workbook.ActiveChart.SetSourceData(Excel_workbook.Sheets['Sheet1'].Range['A1:A10'], xlColumns);这句代码的第一个参数能否与
- 有关DAO350.DLL的问题,哪位知道安装时系统把它装到哪个路径上?
- 怎样判断一个字符串中是否包含另一个字符串??
- 关于VB中使用ACCESS数据库,调用水晶报表出错的问题
- 在VB中,怎样使一段代码执行完毕后再继续下一个过程,如加载文件等,请各位高手赐教,谢谢!
- 如何设置注册表里的默认键值
- 一个晚上,我的信誉变成55,我还不知道怎么一回事?!!
如下:
Dim mydata As Database
Dim myres As Recordsetset mydata=dbengine.opendatabase("e:\temp\temp.mdb",false,false,"ms access;")
set myres=db.openrecordset("表名")
data1.recordname=app.path&"\数据库名.mdb"
app.path是 指程序所在当前目录,路径的改变没有影响。
data1.recordset.movenext
data1.recordset.movefirst
data1.recordset.movelast
data1.recordset.delete
data1.recordset.firdfirst
data1.recordset.findlast
DAO 就是着几条命令。还有一条,但是单词我忘了怎么打了
Set m_Con = CreateObject("ADODB.Connection")
ConnStr = "driver={Microsoft Access Driver (*.mdb)};dbq=" & App.Path & "\school.mdb"
m_Con.Open ConnStr
dim rs as recordset
set rs = new recordset
rs.open("database name","table")
ACCESS2000:
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim res As New ADODB.Recordsetcnn.ConnectionString= "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=" "\YourDB.mdb;Persist Security Info=False"
cnn.Open
Set cmd.ActiveConnection = cnn
cmd.CommandText = strSQL 'strSQL是你的 SQL 语句
set res=cmd.Execute
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim res As New ADODB.Recordsetcnn.ConnectionString= "Provider=Microsoft.Jet.OLEDB 3.51;DataSource=" "\YourDB.mdb;Persist Security Info=False"
cnn.Open
Set cmd.ActiveConnection = cnn
cmd.CommandText = strSQL 'strSQL是你的 SQL 语句
set res=cmd.Execute
dim cnn as new conncetion
dim rst as new recordset
with cnn
.provider="microsoft..jet.oledb.4.0"
.open "c:/1.mdb" '假设acces数据库为c盘1这个文件
end with
with rst
.activeconnection=cnn
.cusorlocation=userclient
.cusortype=openstatic
.open "select ........." '(sql语句)
end with
此为用adodb实现,当然用command也可以,但以上是较高效简单的。
dim rst as new adodb.recordset
with cnn
.provider="microsoft..jet.oledb.4.0"
.open "c:/1.mdb" '假设acces数据库为c盘1这个文件
end with
with rst
.activeconnection=cnn
.cusorlocation=userclient
.cusortype=openstatic
.open "select ........." '(sql语句)
end with
此为用adodb实现,当然用command也可以,但以上是较高效简单的
dim aa as dbenging
Dim mydata As Database
Dim myres As Recordsetset mydata=aa.opendatabase("e:\temp\temp.mdb",false,false,"ms access;")
set myres=mydata.openrecordset("表名")
dim myres as new recordset..........
私下建议用Ado,呵呵
ado有没有资料~
Dim myres As Recordsetset mydata=dbengine.opendatabase("e:\temp\temp.mdb",false,false,"ms access;")
set myres=db.openrecordset("表名")只要引用了DAO,这个代码就不会错的啊!你是不是哪个符号打错了。
能不能告诉我错误号,或错误提示。你的代码中dim aa as dbengine有问题。
dbengine是DAO结构中的最上层,不需要申明,也不能声明。