|
-
Jan 11th, 2008, 09:22 AM
#1
Thread Starter
Addicted Member
[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.
-
Jan 11th, 2008, 10:09 AM
#2
Re: searching for a record using ado.net
What database are you using, and what code are you using to do your search?
-
Jan 11th, 2008, 10:12 AM
#3
Fanatic Member
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)
-
Jan 14th, 2008, 08:50 AM
#4
Thread Starter
Addicted Member
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
-
Jan 14th, 2008, 10:03 AM
#5
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
-
Jan 14th, 2008, 10:33 AM
#6
Re: searching for a record using ado.net
Better yet, don't use either. Use an SQL SELECT query.
-
Jan 15th, 2008, 07:40 AM
#7
Thread Starter
Addicted Member
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.
-
Jan 15th, 2008, 07:44 AM
#8
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.
-
Jan 15th, 2008, 07:57 AM
#9
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|