Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

vonehle (Programmer) (OP)
16 May 06 11:35
I'm still pretty new to VB.NET.

I'm trying to figure out how to display a record from a dataset based on a value entered by the user.  In this case, I have multiple lines with a field called "ID".  The user should be able to type in an "ID" and have the record appear.  I can't seem to figure out how to get it to find the record.  I tried using rows.find, but I must not be using it correctly.

Example:
  Do Until pstrGameID = txtEnterGameID.Text
       drCurrent = DsResults1.tbl_Results.Rows.Find("ID")
       pstrGameID = drCurrent.Item("ID")
  Loop

Additionally, I have an Option Strict conflict with dumping the ID into pstrGameID.  How can I get around this?
Helpful Member!  jebenson (TechnicalUser)
16 May 06 11:52
Another way to do this would be to use a DataView, and take advantage of the DataView's RowFilter property:

Dim dvResults As DataView

dvResults = DsResults1.tbl_Results.DefaultView

dvResults.RowFilter = "ID=" & txtEnterGameID.Text.Trim


I used to rock and roll every night and party every day.  Then it was every other day.  Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys!  Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!  Ye has a choice:  talk like a pirate, or pay yerselves a visit ta Davey Jones' Locker!

vonehle (Programmer) (OP)
16 May 06 12:01
That certainly was an improvement over what I had.  It doesn't crash the program anymore, however, it still displays the first record in the table.

I'm guess that has something to do with this code...

pbndTemp = New Binding("text",DSResults1, "tbl_Results.Home")
lblHomeTeam.DataBindings.Add(pbndTemp)

jebenson (TechnicalUser)
16 May 06 12:12
You will need to change the binding to the DataView rather than to the DataSet.  Then when the DataView is filtered, the correct values should show up in the bound controls.

pbndTemp = New Binding("text",dvResults, "Home")
lblHomeTeam.DataBindings.Add(pbndTemp)

I used to rock and roll every night and party every day.  Then it was every other day.  Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys!  Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!  Ye has a choice:  talk like a pirate, or pay yerselves a visit ta Davey Jones' Locker!

macleod1021 (Programmer)
16 May 06 12:23
I'm not sure why you're using a loop with the find method.  That kinda defeats the purpose.

Get rid of the loop and change:

drCurrent = DsResults1.tbl_Results.Rows.Find("ID")

to:

drCurrent = DsResults1.tbl_Results.Rows.Find(txtEnterGameID.Text)

Then you can use the drCurrent (Row object) to populate your form.  The reason you weren't getting results is because the find was looking for "ID" and not what the user typed in.
vonehle (Programmer) (OP)
16 May 06 15:09
Jeb, your way worked perfectly.  Changes to the data will not work now.  I'm guessing I can't actually use this method because it is not using the dataset?

Macleod, I tried using your idea.  I got an error saying the table didn't have a primary key.  So, I went in the database and made ID the primary key.  Still get the error.  I wonder if I have to recreate the dataset?
jebenson (TechnicalUser)
16 May 06 15:21
Changes to the data in a DataView will propagate back to the underlying DataTable...I do this all the time in my apps.

How are you making the changes?  How are you saving the changes to the database?

I used to rock and roll every night and party every day.  Then it was every other day.  Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys!  Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!  Ye has a choice:  talk like a pirate, or pay yerselves a visit ta Davey Jones' Locker!

macleod1021 (Programmer)
16 May 06 16:15
If you created the dataset programitcally, then you shouldn't have to.  If you created it in the designer, then you'll need to delete it and recreate it so that the new schema will be there.

The only time the updates are automatic is if you're using a datareader.  A dataset/dataview is disconnected.  You have to set up your own update logic and connect it to the dataset.  You need to set up an update statement into an SQLCommand object and then pass that through to the DataSet.UpdateCommand property.
ThatRickGuy (Programmer)
17 May 06 10:35
Another option:

CODE

dim drResults() as datarow = DsResults.tables("tbl_results").select("ID = " & txtEnterGameID.Text)

pstrGameID = drResults(0)("ID")

VB.Net Forum forum796    forum855 ASP.NET Forum
    I believe in killer coding ninja monkeys.

vonehle (Programmer) (OP)
17 May 06 10:41
Thanks Rick, but the way still gives me an error.  

"Option strict on disallows implicit conversions from system.object to string"
ThatRickGuy (Programmer)
17 May 06 11:43
Sorry, I should have caught that, you even said you were using strict.

CODE

pstrGameID = drResults(0)("ID").tostring

-Rick

VB.Net Forum forum796    forum855 ASP.NET Forum
    I believe in killer coding ninja monkeys.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close