DataView question

  • Thread starter Thread starter Woody Splawn
  • Start date Start date
W

Woody Splawn

I have a Winform where I fill a table with an associated dataset. This will
put say 20 records into the table.

I know this is elemental but... I want to see only one record from on my
Winform from the dataset where the SSN = 547703330. SSN is the primary key
for the table. At present I am using code like the following to determine
if the specific record exists in the Dataset.

Dim dtStudents As DataTable
Dim drStudents As DataRow
Dim dvStudents As DataView
Dim intIndex As Integer

dtStudents = DsMain1.Tables("Students")
dvStudents = dtStudents.DefaultView
dvStudents.Sort = "SSN ASC"
intIndex = dvStudents.Find(CObj(547703330))
'MsgBox(dvStudents(intIndex).Row("SSN").ToString)

My MsgBox tells me that the SSN is in the DataSet and is, for example,
Record 47. My question is, how do I now cause my form to only show that
particular record?
 
Hi Woody,

You can try to use the DataView.RowFilter property to get the only row you
need. Have a try at the following codes:

After you get the dataset (ds)

Dim dvStudent as DataView
dtStudent = ds.Tables(0)
dvStudent = New DataView(dtStudent, " SSN = 547703330", " SSN ASC",
DataViewRowState.CurrentRows)
Me.DataGrid1.DataSource = dvStudent

These codes will filter the original DataTable and create a new DataView,
the dvStudent only contains the row which SSN = 547703330. Then you can
pass it to a DataGrid or do as you wish.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi Kevin,
Then you can
pass it to a DataGrid or do as you wish.


That's part of the problem. I do not have this inforamtion in a grid but
they are fields in a Winform.
 
Hi Woody,

If you want to show the information in a DataGrid, you can use:

Me.DataGrid1.DataSource = dvStudent

Or if you want to show the data values in some Textboxes, you may try to
bind the textbox to the dataview. Please see the following codes:

Me.TextBox1.DataBindings.Add("Text", dvStudent, "columnname")

Does this answer your question? If anything is unclear, please feel free to
reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Does this answer your question? If anything is unclear, please feel free
to
reply to the post.


Thank you for responding. Unfortunately, it doesn't give me a good solution
for what I want to do. Perhaps I asked it wrong. I want to be able to
bring numerous records into a table in a dataset but at the click of a
button fix it so that the user is moved to just a certain one. I am doing
this in a windows form with numerous fields on it all from the same table in
the dataset. Isn't there something simpler than rebinding each of those
fields?

Actually I guess I am asking a compound question. One is how to move to
just a certain record and the other is how to restrict the user to just a
certain record. I supposed for the later the solution was a dataview.
There's probably something simpler for just moving to a given record.

To move to a given record and cause the user to see it on screen what is a
simple snipit of code?
 
Thanks Cor,

Woody, if you don't want to create a new DataView or DataRowView for evey
record, you can try the following codes using DataTable.Select()

Dim dtStudent as DataTable = ds.Tables(0)
Dim dr As DataRow() = dtStudent.Select("SSN = 547703330")
Dim r As DataRow = dr(0)
Textbox1.Text = r("student")

The DataTable.Select() method returns an array of rows which includes all
the rows that meets the condition you specified. If there's only one row
meets the condition, get the first row and display its items.

Does this answer your question? If anything is unclear, please feel free to
reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Reply-To: "Cor" <[email protected]>
| From: "Cor" <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.vb
| References: <#[email protected]>
<[email protected]>
<[email protected]>
<c#[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: DataView question
| Date: Fri, 12 Sep 2003 16:49:44 +0200
| Organization: .
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Lines: 14
| Message-ID: <[email protected]>
| NNTP-Posting-Host: 62.131.7.115
| X-Trace: 1063378098 reader22.wxs.nl 1533 62.131.7.115
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!skynet.be!skynet.be!newsgate.cistron.nl!news2.euro.net!newsfeed.wxs.nl!
nova.planet.nl!not-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:136995
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Kevin,
| Maybe Woody is just searching for a dr.item.
| pseudo code
| dr as datarow
| dr = dataset.find(object.key)
| textbox.text = dr.item("Student")
| It have no good sample at hand and you are so busy with this problem,
that
| I think it's better you handle this.
| It is just a gues trying to help you both on the route looking from a
| different view.
|
| Cor
|
|
|
 
Back
Top