Hi All,

I am new to VB.NET so please be gentle with me.

I have the code below which I am trying to add new data to the database but I keep getting error on this line Adodc1.Recordset = rst why do I get this error?

VB Code:
  1. Private Sub frmContacts_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         rst.CursorType = ADODB.CursorTypeEnum.adOpenKeyset
  3.         Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\gh\WindowsApplication10\WindowsApplication10\ContactsDB.mdb" & ";Persist Security Info=False"
  4.  
  5.     End Sub
  6.     Public Sub Add_Contct()
  7.         rst.Open("SELECT * FROM Contacts_Table", Adodc1.ConnectionString, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
  8.         Adodc1.Recordset = rst
  9.         If rst.EOF And rst.BOF Then
  10.             Do While Not rst.EOF
  11.                 rst.AddNew("First_Name", txtFirstName.Text)
  12.                 rst.AddNew("Last_Name", txtLastName.Text)
  13.             Loop
  14.         End If
  15.     End Sub
  16.  
  17.     Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
  18.         Add_Contct()
  19.     End Sub
  20.  
  21.     Private Sub frmContacts_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
  22.        
  23.     End Sub
  24.  
  25.     Private Sub frmContacts_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
  26.         Adodc1 = Nothing
  27.  
  28.         rst = Nothing
  29.     End Sub

Thanks

Loftty