I am a big novice when it comes to ADO.NET and VB.NET so forgive me if I am making this hard to understand.
I have a dataset that has 100+ rows and 12 columns. My table is named "DsInventory1.Inventory" within the dataset.
I am looking for a brief coding example or resource to learn how to loop through each row and check to see if a specific cell value for a specified column within that row matches the string returned from a textbox on my form.
If anyone can point me in the right direction, it would be appreciated.
Thanks

Performing search on dataset
HopeDreamsComeTrue
However, for your situation, you may want to create a new Dataview based on your DataTable with the filtering expression that you need:
Dim myView As New DataView(DsInventory1.Inventory, "ColumnName = '" & TextValue & "'", , DataViewRowState.CurrentRows)
TextFields.DataSource = myView
Arun Narayan
Dim foundRow As DataRow = DsInventory1.Inventory.Rows.Find(desiredString)
Me.BindingContext(DsInventory1, "Inventory").Position = foundRow.ItemArray(0)
and that didn't work.
I'm really not sure at all where you're coming from on your suggestion. There is no "textfields" group and I also don't see a datasource property for any of my text box controls. I don't see why I need a new data view. Could you please elaborate
Thanks.
Nestor N
For instance, this will run just fine:
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
Try
Me.BindingContext(DsInventory1, "Inventory").Position = 0
DisplayRecordPosition()
Catch '...
End Try
End Sub
I just want to add a textbox (txtSearch) and a button (btnSearch) that allows me to enter in a desired primary key and then have the form bind to the position of the record that contains said key. I am understanding that the code below will return one row and that's exactly what I want.
Dim foundRow As DataRow = DsInventory1.Inventory.Select("ColumnName = " & SoughtValue.ToString)
However, I am just not sure how to bind "foundRow" to my form. I was assuming I could use Me.BindingContext(dataset, table).Position and then assign it to the index of whatever row is found in "foundRow" but I"m not sure how to do that.
I guess the concept of creating a new dataview to handle one record is beyond my scope of understanding at this time. I have some ASP.NET books and am kind of learning how to do this out of those as well as a Visual Basic .NET book but that is pretty basic. If there's a good resource online that would describe something similar, feel free to point me in the right direction. I haven't found anything too useful at this point.
Thanks again
in-q-ztiv
This code:
DsInventory1.Inventory.Select("ColumnName = " & SoughtValue.ToString)
will return an array of DataRow objects. Since you are dealing with a primary key, the returned array will only contain one item, so index 0 is your row.
Erymuzuan posted code to use the Find Method of the DataRowCollection. I was saying that my suggestion above did the same thing as his.
I provided a method to create a New DataView simply because I thought it might help you in assigning as a DataSource. With respect to your textboxes, how are you currently binding to them Or are you at all
BlueLou
DataRow foundRow = myDataTable.Rows.Find(textFind.Text);
Console.WriteLine(foundRow[0]);// display the first column
rw-ral
Dim foundRow As DataRow = DsInventory1.Inventory.Select("ColumnName = " & SoughtValue.ToString)
Dim i As IList = CType(DsInventory1.Inventory.Rows, System.ComponentModel.IListSource).GetList()
Me.BindingContext(DsInventory1, "Inventory").Position = i.IndexOf(foundRow)
Sorry I can't help more, hopefully someone can chime in with a more robust solution.
Daniel Chu
I want something similar to this so that I can bind my text fields on my form to the row I get returned from the find/search
Dim foundRow As DataRow = DsInventory1.Inventory.Rows.Find(textFind.Text)
Me.BindingContext(DsInventory1, "Inventory"). = foundRow
I need to find how to bind my form's text controls to the row I get returned. If I could get the index of "foundRow" I could then do this:
Me.BindingContext(DsInventory1, "Inventory").Position = foundRow.indexofrow
Hopefully this is a little more clear. Thanks for your assistance.
danrhee
What I want to do is this:
All the records have a unique value in the specific column I wish to search through (it's the primary key column). When one enters in that value into the textbox on the form, and presses "Search", I want the entire row to be returned that contains that particular value.
Let me know if you need anymore clarification on my part. Thanks for your help.
kaja
Me.Cursor = Windows.Forms.Cursors.WaitCursor()
CurrentTrackingNumber = Me.DataGrid1(DataGrid1.CurrentRowIndex, 0).ToString()
selIndex = DataGrid1.CurrentRowIndex
If IsDBNull(CurrentTrackingNumber) = True Then
MsgBox("No Tracking Number Selected")
Else
Dim checkFrm As Form, Opened As Boolean
For Each checkFrm In Me.MdiChildren
If InStr(checkFrm.Text, CurrentTrackingNumber) Then
checkFrm.Focus()
Opened = True
End If
Next
If Opened = False Then
TicketLoadSetting = 0
Dim frm As New TroubleReport()
frm.MdiParent = Me
Dim RowDS As DataSet = Me.objTroubleReports.Clone()
Dim copyRows() As DataRow = objTroubleReports.Tables("tblTroubleReports").Select("TrackingNumber = " & CurrentTrackingNumber)
Dim custTable As DataTable = RowDS.Tables("tblTroubleReports")
Dim copyRow As DataRow
For Each copyRow In copyRows
custTable.ImportRow(copyRow)
Next
frm.objSelectedTroubleReport.Merge(RowDS, False)
frm.Show()
End If
End If
Me.Cursor = Windows.Forms.Cursors.Default()
Fabio
Thanks for your assistance though. I appreciate it.
Gustavo Valdes
DsInventory1.Inventory.Select("ColumnName = " & SoughtValue.ToString)
that will return an array of DataRow objects.