thuyyeu99 > 04-09-20, 05:49 PM
(04-09-20, 08:56 AM)AnNguyen Đã viết:Mình chỉ xem giao diện của bạn để học hỏi thôi, Code thì có các anh trên đây rồi, mình Pó tay(03-09-20, 10:10 PM)thuyyeu99 Đã viết: hôm nay mới rảnh vào diễn đàn, cám ơn bạn nhiều nhé, để mình test thửRồi bác nhé, rảnh xem code xem các thử cho em và góp ý bổ sung cho em nữa nhé, hì
bạn cấp quyền cho mình nhé
thuyyeu99 > 04-09-20, 06:01 PM
AnNguyen > 04-09-20, 06:27 PM
AnNguyen > 07-09-20, 03:53 PM
(01-09-20, 01:08 PM)Xuân Thanh Đã viết: 2/ Đưa cái định nghĩa rst ra ngoài định nghĩa cmd (Tạo cmd xong mới tạo rst )
Xuân Thanh Đã viết:
Xuân Thanh Đã viết:
ongke0711 > 10-09-20, 03:11 PM
AnNguyen > 10-09-20, 04:40 PM
ongke0711 Đã viết:
ongke0711 Đã viết:
ongke0711 Đã viết:
ongke0711 Đã viết:
Set subform.form.recordset=rst
rst.close
set rst=nothing
ongke0711 > 15-09-20, 01:42 PM
Option Explicit
Private Const adUseClient As Long = 3
Private Const adLockReadOnly As Long = 1
Private Const adStateOpen As Long = 1
Private Const adCmdStoredProc As Long = 4
Private Const adParamOutput As Long = 2
Private Const adOpenDynamic As Long = 2
Private Const adOpenStatic As Long = 3
Public Enum DBaseType
dbSQLServer = 1
dbAccess = 2
End Enum
Public mServerName As String
Public mDatabaseName As String
Public mUserName As String
Public mPassword As String
Public mConnectionString As String
Global oConn As Object
Function ConnectDB(Optional ByVal DBType As DBaseType = 1) As Boolean
On Error GoTo ConnectDBError
Dim strConnectSQL As String
Dim blnNewConnect As Boolean
Dim blnReturn As Boolean
blnReturn = True
blnNewConnect = True
Call BuildConnectionString(DBType)
If Not oConn Is Nothing Then 'Kiem tra xem có Connection chua, có rôi thi dung ket noi cu
If oConn.State And adStateOpen = adStateOpen Then '-> Da có ket noi
blnNewConnect = False
End If
End If
If blnNewConnect Then
Set oConn = New ADODB.Connection
oConn.ConnectionString = mConnectionString
oConn.Open
End If
ConnectDBResume:
ConnectDB = blnReturn
Exit Function
ConnectDBError:
blnReturn = False
Select Case Err.Number
Case -2147467259
MsgBox "Thong so ket noi Database khong dúng.", vbCritical, "Thông báo"
Case -2147217843
MsgBox "Sai ten dang nhap hoac mat khau.", vbCritical, "Thông báo"
Case Else
MsgBox "Có loi phat sinh." & vbCrLf & "Ma loi: " & Err.Number _
& "Noi dung: " & Err.Description, vbCritical, "ConnectDB"
End Select
Resume ConnectDBResume
End Function
Sub CloseConnectDB()
On Error GoTo HandleError
'Dong ket noi toi Database
If Not oConn Is Nothing Then
If (oConn.State And adStateOpen) = adStateOpen Then
oConn.Close
Set oConn = Nothing
End If
End If
Exit Sub
HandleError:
If Err > 0 Then
MsgBox "Có loi phat sinh." & vbCrLf & "Ma loi: " & Err.Number _
& "Noi dung: " & Err.Description, vbCritical, "CloseConnectDB"
Exit Sub
End If
End Sub
Sub BuildConnectionString(ByVal DataBaseType As DBaseType)
Select Case DataBaseType
Case 1 'SQLServer
If Len(mUserName) Then 'Có Username/Pass dang nhap
mConnectionString = "Network Library=DBMSSOCN;" & _
"PROVIDER=SQLOLEDB;DATA SOURCE=" & mServerName & _
";INITIAL CATALOG=" & mDatabaseName & _
";User Id=" & mUserName & ";Password=" & mPassword & ";"
Else
'"Provider=SQLNCLI10;"
mConnectionString = "Network Library=DBMSSOCN;Provider=SQLOLEDB;" & _
"Server=" & mServerName & ";" & _
"Database=" & mDatabaseName & ";" & _
"Trusted_Connection=Yes;"
End If
Case 2 'MS Access
If Len(mPassword) Then
mConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & mDatabaseName & ";" & _
"Jet OLEDB:Database Password=" & mPassword & ";"
Else
mConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & mDatabaseName & _
";Persist Security Info=False;"
End If
Case Else
'Not yet set
End Select
End Sub
Public Function ExecuteSPWithADOCommand(StoredProcName As String, _
ParamArray InputParameters()) As ADODB.Recordset
Dim objCmd As ADODB.Command
Dim rsCmd As ADODB.Recordset
Dim intParam As Integer
Dim value As Variant
'Dim recordsAffected As Long
On Error GoTo ESPError
If ConnectDB() Then
Set objCmd = New ADODB.Command
With objCmd
.ActiveConnection = oConn
.CommandText = StoredProcName
.CommandType = adCmdStoredProc
'Lay tham so
For intParam = LBound(InputParameters) To UBound(InputParameters)
value = InputParameters(intParam)
.Parameters.Append getType(value)
Next
Set ExecuteSPWithADOCommand = .Execute
End With
End If
Exit Function
ESPResume:
On Error Resume Next
Set ExecuteSPWithADOCommand = Nothing
Set objCmd = Nothing
CloseConnectDB
Exit Function
ESPError:
ShowErrorMessages Err, "modKetNoiSQLSv", "ExecuteSPWithADOCommand"
Resume ESPResume
End Function
AnNguyen > 15-09-20, 05:28 PM
AnNguyen > 15-09-20, 06:25 PM
(15-09-20, 01:42 PM)ongke0711 Đã viết: Hàm dưới đây dùng để chạy tất cả các SP mà em thiết kế, không cần phải mỗi SP lại viết cái hàm riêng. Anh thấy em viết cả chục hàm chạy SP.