伊能静 安妮第一:快要动手做的仓库管理系统是VB做客户端程序,服务器用的是MS SQL SERVER 2000

来源:百度文库 编辑:高校问答 时间:2024/04/30 03:55:26
快要动手做的仓库管理系统是VB做客户端程序,服务器用的是MS SQL SERVER 2000,怎么将一个一个的用VB做的窗体连起来,具体点,谢谢

类模块方便:
Option Explicit

Private Con As ADODB.Connection

Private Rs As ADODB.Recordset

Public Rs1 As ADODB.Recordset
Public Rs2 As ADODB.Recordset

Public Rst As ADODB.Recordset

Private Data As Object
Private ConString As String

Private Sub Class_Initialize()
On Error GoTo dbnotopen
Set Con = New ADODB.Connection
ConString = "Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;User ID=sa;Initial Catalog=Sims_four;Data Source=LIRONG"

With Con
.ConnectionString = ConString
.CommandTimeout = 10
.Open
Set Rst = New ADODB.Recordset
End With
Exit Sub

dbnotopen:
If Err = -2147467259 Then
Set Con = Nothing
MsgBox "连接后台数据库失败!" & vbCrLf & vbCrLf & "请检查配置是否完好,数据库sims_four是否存在?", vbOKOnly + vbInformation, "学生信息管理系统"
End
End If

End Sub

Private Sub Class_GetDataMember(DataMember As String, Data As Object)
Set Data = Rs

End Sub

Public Function rsDk(Table As String)
Set Rs = New ADODB.Recordset
With Rs
.Source = Table
.ActiveConnection = Con
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open , , , , adCmdTable
End With

End Function
Public Function rsDk1(Sql As String)
Set Rs1 = New ADODB.Recordset
With Rs1
.Source = Sql
.ActiveConnection = Con
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open , , , , adCmdText
End With
End Function

Public Function rsDk2(Sql As String)
Set Rs2 = New ADODB.Recordset
With Rs2
.Source = Sql
.ActiveConnection = Con
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open , , , , adCmdText
End With

End Function

Private Sub Class_Terminate()
Set Con = Nothing
Set Rs1 = Nothing
Set Rs2 = Nothing
Set Rs = Nothing
Set Rst = Nothing
End Sub
例如保存为RSopen

然后在窗体调用
Set MyLogin = New RsOpen
就OK了,就可以调用数据库进行各种操作了.