|
-
Apr 27th, 2005, 09:58 AM
#1
Thread Starter
Fanatic Member
Need help connecting to DB
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
-
Apr 27th, 2005, 10:03 AM
#2
Re: Need help connecting to DB
before you get too deep into this, I will suggest you use the .NET data access classes as they are tons better than trying to use old ADO in a .NET app.
-
Apr 27th, 2005, 10:07 AM
#3
Thread Starter
Fanatic Member
Re: Need help connecting to DB
Hi,
Thanks for the info, Could you guide me to a good tutorial or show me how to implement my code please?
Thanks
Loftty
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|