software info by softsys

Search   Chat 


Code of ADO using Access as a backend

For This code take 6 command button and 2 text box
********************************************************************************************
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset

'Add button
Private Sub Command1_Click()
Text1.Text = " "
Text2.Text = " "
Text1.SetFocus
End Sub

'Insert button
Private Sub Command2_Click()
Dim str As String
str = "insert into stud values('" & Text1.Text & "' , '" & Text2.Text & "')"
con.Execute str
End Sub

'Move next
Private Sub Command3_Click()
rs.MoveNext
If rs.EOF Then
rs.MoveLast
MsgBox "Last record "
End If
End Sub

'Move previous
Private Sub Command4_Click()
rs.MovePrevious
If rs.BOF Then
rs.MoveFirst
MsgBox " First record"
End If
End Sub

'Delete Button
Private Sub Command5_Click()
Dim str1 As String
str1 = "delete from stud where roll='" & Text1.Text & "' "
MsgBox str1
MsgBox "record deleted"
con.Execute str1
End Sub

'Modify button
Private Sub Command6_Click()
Dim str As String
str = "update stud set name= '" & Text2.Text & " ' where roll = '" & Text1.Text & " ' "
con.Execute str
MsgBox "record modified"
End Sub

'Form Load
Private Sub Form_Load()
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
con.Provider = "Microsoft.jet.oledb.4.0"
con.ConnectionString = "Data source= e:\adotest.mdb"
con.Open
rs.CursorLocation = adUseClient
rs.Open "Stud", con, adOpenDynamic

Set Text1.DataSource = rs
Text1.DataField = "roll"

Set Text2.DataSource = rs
Text2.DataField = "name"

End Sub

Code of ADO Using Oracle as a backend
**************************************************************************************
' General Declaration
Dim con As Connection
Dim rs As Recordset
' Move to next record

Private Sub Command1_Click()
rs.MoveNext
If rs.EOF Then
rs.MoveLast
MsgBox "last record"
End If
End Sub
' Move to previous record

Private Sub Command2_Click()
rs.MovePrevious
If rs.BOF Then
rs.MoveFirst
MsgBox "First Record"
End If
End Sub
'Add button clear contents


Private Sub Command3_Click()
Text1.Text = " "
Text2.Text = " "
End Sub
'Insert button save contents

Private Sub Command4_Click()
Dim str As String
str = "insert into account values('" & Text1.Text & "' , '" & Text2.Text & "')"
con.Execute str
MsgBox "New record added"
End Sub
'Delete button

Private Sub Command5_Click()
Dim str As String
str = "delete from account where accountno= '" & Text2.Text & "' "
con.Execute str
MsgBox "record deleted"
End Sub
'Modify Button

Private Sub Command6_Click()
Dim str As String
str = "update account set balance= '" & Text1.Text & " ' where accountno = '" & Text2.Text & "' "
con.Execute str
MsgBox "record modified"
End Sub
'Move first

Private Sub Command7_Click()
rs.MoveFirst
End Sub
'Move last

Private Sub Command8_Click()
rs.MoveLast
End Sub

' form load ... code for connectivity
Private Sub Form_Load()
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
con.ConnectionString = "Provider=MSDAORA.1;Password=tiger;User ID=scott;Data Source=mitsom;Persist Security Info=True"
con.Open
rs.CursorLocation = adUseClient
rs.Open "account", con, adOpenDynamic

Set Text1.DataSource = rs
Text1.DataField = "balance"

Set Text2.DataSource = rs
Text2.DataField = "accountno"

End Sub



Calculator Code