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:
Private Sub frmContacts_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load rst.CursorType = ADODB.CursorTypeEnum.adOpenKeyset Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\gh\WindowsApplication10\WindowsApplication10\ContactsDB.mdb" & ";Persist Security Info=False" End Sub Public Sub Add_Contct() rst.Open("SELECT * FROM Contacts_Table", Adodc1.ConnectionString, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic) Adodc1.Recordset = rst If rst.EOF And rst.BOF Then Do While Not rst.EOF rst.AddNew("First_Name", txtFirstName.Text) rst.AddNew("Last_Name", txtLastName.Text) Loop End If End Sub Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Add_Contct() End Sub Private Sub frmContacts_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing End Sub Private Sub frmContacts_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed Adodc1 = Nothing rst = Nothing End Sub
Thanks
Loftty




Reply With Quote