用VB编下个程序,关于数据库的问题!!大家一定要帮我呀,SOS,谢谢!!

luckyjeery 2002-05-20 02:21:48
用VB编下个程序
第一个FORM
有个TEXT框可以输入数据库的名字
一个按钮用作建一个VB的数据库
另一个按钮用作打开一个VB的数据库
第一个FORM
对于新建的数据库可以添加。删除
对于打开的数据库可以追加。删除
...全文
4 点赞 收藏 11
写回复
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
daryl715 2002-05-20
不客气
回复
luckyjeery 2002-05-20
thank you very much!!
回复
daryl715 2002-05-20
只不过是后台数据库不一样

不同的数据库只要更换相应的连接字符串cnnstr就可以了

回复
daryl715 2002-05-20
只不过是后台数据库不一样

不同的数据库只要更换相应的连接字符串cnnstr就可以了

回复
luckyjeery 2002-05-20
这么复杂呀!!要是简单的用VF做数据那该怎么办!!
回复
liuyufeng 2002-05-20
dim dbdata as database
dim rst as recordset


text1.text=rst(fileds(index))
回复
daryl715 2002-05-20
添加记录
Dim cnn1 As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cnnstr As String
cnnstr = " provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;"
cnn1.Open cnnstr

With rst
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "select * from stu", cnnstr
.AddNew
.Fields("字段1") = "1"
.Fields("字段2") = "2"
.Fields("字段3") = "3"
.Fields("字段4") = "4"
.Fields("字段5") = "5"
.Update
.UpdateBatch adAffectAllChapters
End With
Set Form1.MSHFlexGrid1.DataSource = rst
rst.Close
cnn1.Close

删除记录

'删除第一条数据
Dim cnn1 As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cnnstr As String
cnnstr = " provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;"
cnn1.Open cnnstr

With rst
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "select * from stu", cnnstr
.Delete adAffectCurrent
.Update
.UpdateBatch adAffectAllChapters
End With
Set Form1.MSHFlexGrid1.DataSource = rst
rst.Close
cnn1.Close

用SQL选择删除数据
Dim cnn1 As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cnnstr As String
Dim i As Integer
cnnstr = " provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;"
cnn1.Open cnnstr

With rst
.CursorType = adOpenForwardOnly
.LockType = adLockOptimistic
.Open "select * from stu where 字段1='" & "r" & "'", cnnstr
.Delete adAffectCurrent
.Update
.UpdateBatch adAffectAllChapters
End With
Set Form1.MSHFlexGrid1.DataSource = rst
Next i
rst.Close
cnn1.Close


删除SQL搜索到的多条数据
Dim cnn1 As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cnnstr As String
Dim i As Integer
Dim a As Integer
cnnstr = " provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;"
cnn1.Open cnnstr

rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
rst.Open "select * from stu where 字段1='" & "r" & "'", cnnstr
Do Until rst.EOF
rst.Delete adAffectCurrent
rst.Update
rst.UpdateBatch adAffectAllChapters
rst.MoveNext
Loop
set Form1.MSHFlexGrid1.DataSource = rst
rst.Close
cnn1.Close

删除所有数据
Dim cnn1 As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cnnstr As String

cnnstr = " provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;"
cnn1.Open cnnstr

rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
rst.Open "select * from stu ", cnnstr
Do Until rst.EOF
rst.Delete
rst.Update
rst.UpdateBatch adAffectAllChapters
rst.MoveNext
Loop

Set Form1.MSHFlexGrid1.DataSource = rst
rst.Close


编辑记录
修改一条记录
Dim cnn1 As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cnnstr As String
Dim i As Integer
Dim a As Integer
cnnstr = " provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;"
cnn1.Open cnnstr

rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
rst.Open "select * from stu where 字段1= '" & "text1" & "'", cnnstr

rst.Update
rst.Fields("字段1") = Me.Text1.Text
rst.Fields("字段2") = Me.Text2.Text
rst.Fields("字段3") = Me.Text3.Text
rst.Fields("字段4") = Me.Text4.Text
rst.Fields("字段5") = Me.Text5.Text
rst.UpdateBatch adAffectAllChapters

Set Form1.MSHFlexGrid1.DataSource = rst
rst.Close
cnn1.Close

修改多条记录
Dim cnn1 As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cnnstr As String
Dim i As Integer
Dim a As Integer
cnnstr = " provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;"
cnn1.Open cnnstr

rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
rst.Open "select * from stu where 字段1= '" & "高" & "'", cnnstr
Do Until rst.EOF
rst.Update
rst.Fields("字段1") = Me.Text1.Text
rst.Fields("字段2") = Me.Text2.Text
rst.Fields("字段3") = Me.Text3.Text
rst.Fields("字段4") = Me.Text4.Text
rst.Fields("字段5") = Me.Text5.Text
rst.UpdateBatch adAffectAllChapters
rst.MoveNext
Loop
Set Form1.MSHFlexGrid1.DataSource = rst
rst.Close

回复
liuyufeng 2002-05-20
dim dbdata as database
回复
daryl715 2002-05-20
添加记录
Dim cnn1 As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cnnstr As String
cnnstr = " provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;"
cnn1.Open cnnstr

With rst
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "select * from stu", cnnstr
.AddNew
.Fields("字段1") = "1"
.Fields("字段2") = "2"
.Fields("字段3") = "3"
.Fields("字段4") = "4"
.Fields("字段5") = "5"
.Update
.UpdateBatch adAffectAllChapters
End With
Set Form1.MSHFlexGrid1.DataSource = rst
rst.Close
cnn1.Close

删除记录

'删除第一条数据
Dim cnn1 As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cnnstr As String
cnnstr = " provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;"
cnn1.Open cnnstr

With rst
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "select * from stu", cnnstr
.Delete adAffectCurrent
.Update
.UpdateBatch adAffectAllChapters
End With
Set Form1.MSHFlexGrid1.DataSource = rst
rst.Close
cnn1.Close

用SQL选择删除数据
Dim cnn1 As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cnnstr As String
Dim i As Integer
cnnstr = " provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;"
cnn1.Open cnnstr

With rst
.CursorType = adOpenForwardOnly
.LockType = adLockOptimistic
.Open "select * from stu where 字段1='" & "r" & "'", cnnstr
.Delete adAffectCurrent
.Update
.UpdateBatch adAffectAllChapters
End With
Set Form1.MSHFlexGrid1.DataSource = rst
Next i
rst.Close
cnn1.Close


删除SQL搜索到的多条数据
Dim cnn1 As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cnnstr As String
Dim i As Integer
Dim a As Integer
cnnstr = " provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;"
cnn1.Open cnnstr

rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
rst.Open "select * from stu where 字段1='" & "r" & "'", cnnstr
Do Until rst.EOF
rst.Delete adAffectCurrent
rst.Update
rst.UpdateBatch adAffectAllChapters
rst.MoveNext
Loop
set Form1.MSHFlexGrid1.DataSource = rst
rst.Close
cnn1.Close

删除所有数据
Dim cnn1 As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cnnstr As String

cnnstr = " provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;"
cnn1.Open cnnstr

rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
rst.Open "select * from stu ", cnnstr
Do Until rst.EOF
rst.Delete
rst.Update
rst.UpdateBatch adAffectAllChapters
rst.MoveNext
Loop

Set Form1.MSHFlexGrid1.DataSource = rst
rst.Close


编辑记录
修改一条记录
Dim cnn1 As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cnnstr As String
Dim i As Integer
Dim a As Integer
cnnstr = " provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;"
cnn1.Open cnnstr

rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
rst.Open "select * from stu where 字段1= '" & "text1" & "'", cnnstr

rst.Update
rst.Fields("字段1") = Me.Text1.Text
rst.Fields("字段2") = Me.Text2.Text
rst.Fields("字段3") = Me.Text3.Text
rst.Fields("字段4") = Me.Text4.Text
rst.Fields("字段5") = Me.Text5.Text
rst.UpdateBatch adAffectAllChapters

Set Form1.MSHFlexGrid1.DataSource = rst
rst.Close
cnn1.Close

修改多条记录
Dim cnn1 As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cnnstr As String
Dim i As Integer
Dim a As Integer
cnnstr = " provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;"
cnn1.Open cnnstr

rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
rst.Open "select * from stu where 字段1= '" & "高" & "'", cnnstr
Do Until rst.EOF
rst.Update
rst.Fields("字段1") = Me.Text1.Text
rst.Fields("字段2") = Me.Text2.Text
rst.Fields("字段3") = Me.Text3.Text
rst.Fields("字段4") = Me.Text4.Text
rst.Fields("字段5") = Me.Text5.Text
rst.UpdateBatch adAffectAllChapters
rst.MoveNext
Loop
Set Form1.MSHFlexGrid1.DataSource = rst
rst.Close

回复
luckyjeery 2002-05-20
ADO!!!谢谢!
回复
daryl715 2002-05-20
你要用什么方式呢
比如说ADO?ODBC?还是?
回复
发动态
发帖子

1180

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
社区公告
暂无公告