Results 1 to 15 of 15

Thread: Find a record in ADO .NET

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    MD
    Posts
    182

    Find a record in ADO .NET

    Might be very simple to everyone. But I need it soon. No time to research.

    VB Code:
    1. Dim ADOConOle As OleDb.OleDbConnection
    2.     ADOConOle = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Application.StartupPath & "\Accounts.mdb")
    3.     Dim rsLocal As New OleDb.OleDbDataAdapter
    4.     Dim rsCurrent As New DataSet
    5.     rsLocal.SelectCommand = New OleDb.OleDbCommand("SELECT * FROM CUSTOMER", ADOConOle)
    6.  
    7.     txtCustID.DataBindings.Add("text", rsCurrent.Tables(0), "Cust_Id")
    8.     txtName.DataBindings.Add("text", rsCurrent.Tables(0), "Name")
    9.     txtAddress1.DataBindings.Add("text", rsCurrent.Tables(0), "Address1")
    10.     txtAddress2.DataBindings.Add("text", rsCurrent.Tables(0), "Address2")
    11.     txtAddress3.DataBindings.Add("text", rsCurrent.Tables(0), "Address3")
    I just want to do display a record (like Find method in ADO) for the entered ID in txtCustID field.

    Thanks

    Susindran

  2. #2
    Lively Member
    Join Date
    Sep 2002
    Location
    Belgium
    Posts
    99
    Hello,

    you need to use a dataview so you can sort/filter a dataset.

    Look :

    VB Code:
    1. Dim dv as dataview = ds.tables(0).defaultview
    2.  
    3. dv.RowFilter = "City = 'Berlin'"

    HTH !

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    MD
    Posts
    182
    Does it Filter (like in ADO) or Find?

    Thanks

    Susindran

  4. #4
    Lively Member
    Join Date
    Sep 2002
    Location
    Belgium
    Posts
    99
    It filters. But I don't see the difference between 'find' and 'filter'.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    MD
    Posts
    182
    How do I bind to the text fields again with the found record?

    Thanks

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    MD
    Posts
    182
    Any help on this?

  7. #7
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    Are you trying to search you dataset for a row say with the ID "10" then return the column values for that row?

    Is the column ID your primary key in your database?
    Last edited by Hole-In-One; Mar 9th, 2004 at 10:04 AM.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    MD
    Posts
    182
    You are exactly correct.

    Cust_Id is the Primary Key in table CUSTOMER.

    I am able to bind and navigate it. But unable to find a record (also not able to save it).

    I couldn't find any help in any site or book regarding finding a record and binding it back to controls.

    Thanks

  9. #9
    Member
    Join Date
    Mar 2004
    Posts
    39
    It has to be possible as the typed Datasets has a built in function for each table where you can find a row by using the primary key. So for example if a table has a primary key named CustomerID a typed dataset will have a function for that table named FindByCustomerID.

    Create a typed dataset using the drag and drop in a project and search for that function to see how its done if you don't want to go with a typed dataset yourself.

    /Nisse

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    MD
    Posts
    182
    I am new to .Net. Can you post with sample code?

    Thanks

  11. #11
    Member
    Join Date
    Mar 2004
    Posts
    39
    Create a typed dataset using the drag and drop in a project and search for that function to see how its done if you don't want to go with a typed dataset yourself.
    Create a table in for example SQL and give it a primary key. Drag the table from the server explorer (next to the toolbox) in VS and drop it on a form. A connection to the database and a dataadapter will be created. Rightclick the dataadapter and choose "generate dataset". You know have yourself a typed dataset. Enter the code and look for the FindByXXXX function where XXXX is the name of your primary key column.

    /Nisse

  12. #12
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi unisse,

    "Create a table in for example SQL and give it a primary key. Drag the table from the server explorer (next to the toolbox) in VS and drop it on a form."


    I'm completely lost on this. Where exactly is the "Server Explorer"? I have nothing next to the toolbox.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  13. #13
    Member
    Join Date
    Mar 2004
    Posts
    39
    If its not visible next to the toolbox, it can be found here:

    View -> Server Explorer.

  14. #14
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi unisse,

    Many thanks. I shall enjoy looking at that!!
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  15. #15
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    "Create a table in for example SQL and give it a primary key. Drag the table from the server explorer (next to the toolbox) in VS and drop it on a form."

    Don't forget to rightclick on the DataConnection node in the Server Explorer to create a reference to your database.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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