JAYASHREE ORACLE CERTIFIED JAIN UNIVERSITY

Thursday, September 23, 2010

VB CODE to HANDLE DATABASE USING ADODC1

Private Sub cmdaddnew_Click()
Adodc1.Recordset.AddNew
End Sub

Private Sub cmdCancel_Click()
txttitle.Text = ""
txtpublisher.Text = ""
txtauthor.Text = ""


txtisbn.Text = ""
txtyr.Text = ""
End Sub

Private Sub cmddel_Click()
Confirm = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Deletion Confirmation")
If Confirm = vbYes Then
Adodc1.Recordset.Delete
MsgBox "Record Deleted!", , "Message"
Else
MsgBox "Record Not Deleted!", , "Message"
End If
End Sub

Private Sub cmdedit_Click()
txtisbn.SetFocus

End Sub

Private Sub cmdfind_Click()



SQL = "Select * from books where isbn=" & txtisbn.Text
'create a connection
Dim cn As New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\jay\Desktop\VB\LIB.MDB;Persist Security Info=False"
'create a recordset
Dim rs As New ADODB.Recordset
'open the connection
cn.Open
'execute the sql statement
Set rs = cn.Execute(SQL)

If rs.EOF Then
MsgBox ("Record not Found")
Else

txttitle.Text = rs(1)
txtauthor.Text = rs(2)
txtpublisher.Text = rs(3)
txtyr.Text = rs(4)

End If
'Close Connection
' cn.Close
End Sub

Private Sub cmdmovenext_Click()
If Not Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MovePrevious
End If
End If
End Sub

Private Sub cmdmoveprev_Click()
If Not Adodc1.Recordset.BOF Then
Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF Then
Adodc1.Recordset.MoveNext
End If
End If
End Sub

Private Sub cmdsave_Click()
' Adodc1.Recordset.Update

Adodc1.Recordset.Fields("ISBN") = txtisbn.Text
Adodc1.Recordset.Fields("title") = txttitle.Text
Adodc1.Recordset.Fields("author") = txtauthor.Text
Adodc1.Recordset.Fields("publisher") = txtpublisher.Text
' Adodc1.Recordset.Fields("year") = txtyr.Text
Adodc1.Recordset.Update

MsgBox ("One Record Saved")
End Sub

Private Sub cmdstop_Click()

End Sub

Private Sub DataCombo1_Click(Area As Integer)

' SQL = "Select * from books" + " where author= ' " + DataCombo1 + " ' "
' Adodc1.Refresh
' 'create a connection
' Dim cn As New ADODB.Connection
' cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\jay\Desktop\VB\LIB.MDB;Persist Security Info=False"
' 'create a recordset
' Dim rs As New ADODB.Recordset
' 'open the connection
' cn.Open
' 'execute the sql statement
' Set rs = cn.Execute(SQL)
'
' Set DataGrid1.DataSource = rs


Adodc1.RecordSource = " Select * from books " & " where title= ' " + DataCombo1 + " ' "
txtisbn.Text = Adodc1.Recordset.Fields(0)
txttitle.Text = Adodc1.Recordset.Fields(1)
txtauthor.Text = Adodc1.Recordset.Fields(2)
txtpublisher.Text = Adodc1.Recordset.Fields(3)
txtyr.Text = Adodc1.Recordset.Fields(4)
' Adodc1.Refresh



'Close Connection
' cn.Close

End Sub





Private Sub txttitle_gotfocus()
If IsNumeric(txtisbn.Text) = False Then

MsgBox "Type Error", vbCritical
txtisbn.Text = ""
txtisbn.SetFocus

Exit Sub

End If


End Sub



Private Sub txtyr_LostFocus()
If IsDate(txtyr.Text) = False Then
MsgBox "enter in date format dd/mm/yy", vbCritical
End If
End Sub

No comments:

Post a Comment