Accessing SQL Server Through DMO
Accessing SQL Server Through DMO
Page
SQLGeneral.BAS ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'This is a sample for connecting Visual Basic & SQL Server 6.5 'Using DMO 'Author : Raja B ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Option Explicit Public oSQLServer As New SQLOLE.SQLServer Public oDatabase As SQLOLE.Database This is your SQL Server ( C_BRAIN) This is the Database to use
MdiMain.frm Option Explicit Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer) oSQLServer.DisConnect Cancel = False End Sub Private Sub mnuExit_Click() End End Sub Private Sub mnuProcess_Click(Index As Integer) Select Case Index Case 1: frmCustomer.Show Case 2: frmProduct.Show Case 3 frmInvoice.Show End Select End Sub
K7 Computing
Raja.B
Page
K7 Computing
Raja.B
Page
K7 Computing
Raja.B
Page
Private Sub cmdAdd_Click() Call ClearAllTextBoxes bAddMode = True cmdAdd.Visible = False cmdOK.Visible = True cmdEdit.Visible = False cmdDelete.Visible = False EnableNavigation (False) End Sub Private Sub cmdDelete_Click() This function will delete the current record after the confirmation Dim strSQLDelete As String Dim nReturn As Integer nReturn = MsgBox("Are you sure to Delete this current Record..?" & _ vbCrLf & "Press 'Yes' to Delete , 'No' to Cancel the operation", vbYesNo, "Confirmation") If (nReturn = vbYes) Then strSQLDelete = "DELETE FROM tblCustomer WHERE CustomerID = " & CStr(nCustomerID) Call oDatabase.ExecuteImmediate(Command:=strSQLDelete) qryResult.Refresh nCols = qryResult.Columns nRows = qryResult.Rows If (nRows > 0) Then nCurrentRow = 1 bEnableNavigate = True EnableNavigation (True) Call ShowCustomerAddress Else EnableNavigation (False) bEnableNavigate = False End If End If End Sub
K7 Computing
Raja.B
Page
K7 Computing
Raja.B
Page
K7 Computing
Raja.B
Page
This sample is written in Visual Basic 5.0 Here frmLogim.frm is the ultimate code for loging into your SQL Server. [Here the Server name in coded as C_BRAIN]. Code in frmCustomer.frm demonstrates record navigation, adding a new record , editing the Current record and delete the current record.
K7 Computing
Raja.B