PC Review


Reply
Thread Tools Rate Thread

In a DataTable/DataSet is there a way to search 1 particular row?

 
 
=?Utf-8?B?VGVycmFuY2U=?=
Guest
Posts: n/a
 
      13th Sep 2004
Hello all, I have a problem I was hoping someone could help me out with. Ok,
in my Sql Server Database I'm searching through a table for a particular
value that a user enters(e.g. nameid ). The problem is there are several
nameid's in 1 row of data that I have to search and it's possible for that
nameid to be located in more than 1 place in the table. In my listview what
I'm trying to do is have it where, if a user clicks on row the program will
search that row for that nameid and pull back the necessary picture. Note:
the data in my listview contains all the rows where that nameid is located.
The reason why I had to bring back the other nameid' is because there are
columns such nameid1, nameid2, and so on. In my code, I've been able to
indicate the column id that he user double-click on but I can't cycle
through each column to find the nameid without the code going through the
first row. For example, If two records are returned and I double-click on the
second my code goes through the first row first due to a 'For Each' loop that
I'm using for the datarow. I hope I haven't made this too cofusing. Here is
some of the code:

'place the index of the choosen row into this variable
Dim choosenRow As String =
lvResult.SelectedItems(0).Text.ToString()
'variable to hold the current index as we
'loop through each row
Dim tempString As String

Do Until iCounter = mDataTable.Rows.Count

tempString = mDataTable.Rows(iCounter)("plineupid").ToString()
CompareResult = String.Compare(choosenRow, tempString)

If (CompareResult = 0) Then
For Each myDataRow In mDataSet.Tables("plineup").Rows()
For iLoop = 0 To myDataRow.Table.Columns.Count() - 1

If myDataRow.Item(iLoop) = txtSysid.Text Then

Dim imageStream As System.IO.FileStream

imageStream = New System.IO.FileStream
(configClass.frmMDirectory & _
"\" & myDataRow.Item(iLoop) & "." &
myDataRow.Item(iLoop + 1), System.IO.FileMode.Open, _
System.IO.FileAccess.Read)
'set the image for the picturebox to reduce or
to expand
'to fit the size of the Picturebox.
imgName.SizeMode = PictureBoxSizeMode.StretchImage
imgName.Image =
System.Drawing.Image.FromStream(imageStream)
Exit For
End If
Next
'Next
Exit Do
End If

iCounter += 1 'increment iCounter variable
Loop

Please help....
--
TC
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Sep 2004
Terrance,

There are three methods in Adonet to find records and they all create a
collection of datarows or a single datarow.

Only two will in my idea fit your problem those are

Datatable.select 'static filter
http://msdn.microsoft.com/library/de...electtopic.asp

Dataview.rowfilter 'the fastest and a dynamic filter
http://msdn.microsoft.com/library/de...ilterTopic.asp

After that you have to loop through the collection of course.

The third is the datarow.find however just for one row with the primary key.

I hope this helps,

Cor

"Terrance" <(E-Mail Removed)>
> Hello all, I have a problem I was hoping someone could help me out with.

Ok,
> in my Sql Server Database I'm searching through a table for a particular
> value that a user enters(e.g. nameid ). The problem is there are several
> nameid's in 1 row of data that I have to search and it's possible for that
> nameid to be located in more than 1 place in the table. In my listview

what
> I'm trying to do is have it where, if a user clicks on row the program

will
> search that row for that nameid and pull back the necessary picture. Note:
> the data in my listview contains all the rows where that nameid is

located.
> The reason why I had to bring back the other nameid' is because there are
> columns such nameid1, nameid2, and so on. In my code, I've been able to
> indicate the column id that he user double-click on but I can't cycle
> through each column to find the nameid without the code going through the
> first row. For example, If two records are returned and I double-click on

the
> second my code goes through the first row first due to a 'For Each' loop

that
> I'm using for the datarow. I hope I haven't made this too cofusing. Here

is
> some of the code:
>
> 'place the index of the choosen row into this variable
> Dim choosenRow As String =
> lvResult.SelectedItems(0).Text.ToString()
> 'variable to hold the current index as we
> 'loop through each row
> Dim tempString As String
>
> Do Until iCounter = mDataTable.Rows.Count
>
> tempString =

mDataTable.Rows(iCounter)("plineupid").ToString()
> CompareResult = String.Compare(choosenRow, tempString)
>
> If (CompareResult = 0) Then
> For Each myDataRow In

mDataSet.Tables("plineup").Rows()
> For iLoop = 0 To myDataRow.Table.Columns.Count() - 1
>
> If myDataRow.Item(iLoop) = txtSysid.Text Then
>
> Dim imageStream As System.IO.FileStream
>
> imageStream = New System.IO.FileStream
> (configClass.frmMDirectory & _
> "\" & myDataRow.Item(iLoop) & "." &
> myDataRow.Item(iLoop + 1), System.IO.FileMode.Open, _
> System.IO.FileAccess.Read)
> 'set the image for the picturebox to reduce or
> to expand
> 'to fit the size of the Picturebox.
> imgName.SizeMode =

PictureBoxSizeMode.StretchImage
> imgName.Image =
> System.Drawing.Image.FromStream(imageStream)
> Exit For
> End If
> Next
> 'Next
> Exit Do
> End If
>
> iCounter += 1 'increment iCounter variable
> Loop
>
> Please help....
> --
> TC



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Sep 2004
doh.............

The dataview does not create directly a datarow collection however you can
loop throug it using the datarowview,

Sorry

Cor


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to fix A DataTable named 'Tag2' already belongs to this DataSet.(XML/Datatable) frodenekkoy@hotmail.com Microsoft Dot NET 0 8th Jul 2008 09:14 AM
Copying records from datatable to datatable in dataset tshad Microsoft C# .NET 1 24th Jun 2008 02:39 AM
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ASP .NET 2 31st Oct 2003 02:05 PM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ASP .NET 2 31st Oct 2003 03:42 AM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft Dot NET Framework 2 31st Oct 2003 03:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:24 PM.