Results 1 to 9 of 9

Thread: [RESOLVED] searching for a record using ado.net

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2007
    Posts
    228

    Resolved [RESOLVED] searching for a record using ado.net

    how do i search using table.rows.find
    I get this message telling me there is no primary key. I have set a primary key in the DB its self not in code.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: searching for a record using ado.net

    What database are you using, and what code are you using to do your search?

  3. #3
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: searching for a record using ado.net

    Here You
    Code:
    dtable = ds.Tables("yourTable")
                Dim drow As DataRow
                dcolumn(0) = dtable.Columns(0)
                dtable.PrimaryKey = dcolumn
                drow = dtable.Rows.Find(textbox1.Text)
    
                txtname2.Text = drow(1)
                txtname3.Text = drow(2)
                txtname4.Text = drow(3)

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2007
    Posts
    228

    Re: searching for a record using ado.net

    here is my code here. The sort order works. Just not the find. So when i click on the button must only display the result in the datagridview
    Code:
          Dim dv As New DataView
            dv = KeyGen.DefaultView
            dv.Sort = "Name"
            Dim dRows As DataRowView() = dv.FindRows("Mark")
            Dim x As Integer = dv.Find("Mark")
            If x = -1 Then
    
    
    
            Else
    
                DataGridView1.DataSource = KeyGen
    
    
    
            End If

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: searching for a record using ado.net

    don't use the .Find.... it only searches on the PKey, if I remember right.... Use the .Select method instead... it returns an array of DataRows that match the criteria. And you can use more than one field in the criteria.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: searching for a record using ado.net

    Better yet, don't use either. Use an SQL SELECT query.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2007
    Posts
    228

    Re: searching for a record using ado.net

    OK i have used the Select Query. It retrieves the records from the DB but inserts them at the bottom of the datagridview without clearing all the records first.
    Code:
       CN.Open()
            DataAdapter = New OleDbDataAdapter("Select * From Keygen WHERE name='Mark'", CN)
            CommandBuilder = New OleDbCommandBuilder(DataAdapter)
            DataAdapter.Fill(KeyGen)
            DataGridView1.DataSource = KeyGen
            DataGridView1.DataMember = KeyGen.TableName
            CN.Close()
    I need to only display the results consisting of "mark" in the datagridview. I have tried to clear the grid. I get an error saying cant clear.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: searching for a record using ado.net

    You need to Clear the DataTable, otherwise you're going to be adding the new records to the existing records. Also, if the table is already bound to the grid then why are you binding it again? Do you have to retune your radio every time the station plays a new song? No. Once the table is bound it's bound. If the data in the table changes then the grid will reflect that, which is the whole point of binding.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2007
    Posts
    228

    Re: searching for a record using ado.net

    Thank you all for your help. Its working. I better go read up on ado.net

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