Results 1 to 3 of 3

Thread: Need help connecting to DB

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    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:
    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

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    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
  •  



Click Here to Expand Forum to Full Width