Results 1 to 5 of 5

Thread: OleDbDataAdapter Help!!!! (RESOLVED)

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    144

    Red face OleDbDataAdapter Help!!!! (RESOLVED)

    Hey all need some help!!

    At the moment i have a simple form that retrieves data from a database using a dataAdapter using SQL fills a DataSet then binds the data to textboxes.

    What i want to do is create a textbox called 'txtSearch.text then when 'btnSearch' button is clicked it will retrieve that record and display in the textboxes

    i think i will have to use a WHERE clause in the SQL in the OleDbDataAdapter to specify a specific Student_ID and direct it to the textbox txtsearch (How do i do tha?)

    not sure how to add parameters to my SQL in the dataAdpater to do this can anyone edit my code so that can be done.... thanks

    VB Code:
    1. 'Declare Objects...
    2.     Dim myAdapter As OleDbDataAdapter = New OleDbDataAdapter( _
    3.         "SELECT Student_ID, Student_Fname, Student_Lname, Date_of_Birth, Address, Post_Code, Telephone_No " & _
    4.         "FROM Student", OleDbConnection1)
    5.  
    6.     Dim myDS As DataSet
    7.     Dim myDV As DataView
    8.  
    9.     Private Sub FillDataSetAndView()
    10.         'Initialize a new instance of the DataSet object...
    11.         myDS = New DataSet
    12.  
    13.         'Set Connection and Fill DataSet object...
    14.         myAdapter.SelectCommand.Connection = OleDbConnection1
    15.         myAdapter.Fill(myDS, "Student")
    16.  
    17.         'Set the DataView object to the DataSet
    18.         myDV = New DataView(myDS.Tables("Student"))
    19.     End Sub
    20.  
    21.     Private Sub BindFields()
    22.  
    23.         'Clear any previous bindings...
    24.         txtStudentID.DataBindings.Clear()
    25.         txtFname.DataBindings.Clear()
    26.         txtSname.DataBindings.Clear()
    27.         dtpDOB.DataBindings.Clear()
    28.         txtAddress.DataBindings.Clear()
    29.         txtPostCode.DataBindings.Clear()
    30.         txtTelephone.DataBindings.Clear()
    31.  
    32.         'Add new bindings to the DataView object...
    33.         txtStudentID.DataBindings.Add("Text", myDV, "Student_ID")
    34.         txtFname.DataBindings.Add("Text", myDV, "Student_Fname")
    35.         txtSname.DataBindings.Add("Text", myDV, "Student_Lname")
    36.         dtpDOB.DataBindings.Add("Text", myDV, "Date_of_Birth")
    37.         txtAddress.DataBindings.Add("Text", myDV, "Address")
    38.         txtPostCode.DataBindings.Add("Text", myDV, "Post_Code")
    39.         txtTelephone.DataBindings.Add("Text", myDV, "Telephone_No")
    40.  
    41.     End Sub
    42.  
    43.     Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
    44.         'Fill the dataset and bind the field...
    45.         FillDataSetAndView()
    46.         BindFields()
    47.     End Sub
    Last edited by JamesBowtell; Feb 2nd, 2005 at 07:55 AM.

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