JPERKS1985
asked on
Finding which Row holds a certain string in one of it's cell in a datatable. VB.NET
I need to determine which row has a value in one of its cells in a specific column with a datatable. The value is known before hand as also is the column. The reason is I need to alter a value within the same row only two columns over. I'd like this in vb.net thanks.
I appologize, I forgot one crucial dimension:
For I as Integer = 0 to myarray.rows
if myarray.cells(I, KnownColumn).value = KnownValue then Exit For
Next I
myarray.cells(I, KnownColumn + 2).value = AlteredValue
(forgot the .value)
Cheers JPerks
For I as Integer = 0 to myarray.rows
if myarray.cells(I, KnownColumn).value = KnownValue then Exit For
Next I
myarray.cells(I, KnownColumn + 2).value = AlteredValue
(forgot the .value)
Cheers JPerks
ASKER
hmm says 'cells' is not a member of 'System.Data.DataTable'. I'm very new to this do you know whats wrong?
This is how dtform is declared Public dtForm As DataTable
This is how dtform is declared Public dtForm As DataTable
I'm sorry I thought you were using an msflexigrid. As long as you aren't doing any threading, which you shouldn't be as a new program, you should change it so that you are using a grid instead of a System.Data.DataTbale. These deal with the raw memory stored in ram, and get pretty complicated. They are the foundation but you don't need to deal directly with them. It would be like trying to make a bitmap picture in notepad by setting all the individual pixels when you could draw it using paint. I would look at other dataTable types, like an MSFlexiGrid or a simple 2 dimentional array to store your data. Most things you would normally export to recognise both these formats, such as Excel and DAO recordsets.
ASKER
haah it is threaded.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Created a solution
Dim cName As TextBox = CType(sender, System.Windows.Forms.TextB ox)
cName.Name = CType(sender, System.Windows.Forms.TextB ox).Name
Dim DRow As DataRow
For Each DRow In dtForm.Rows
If DRow(2).Item = cName.Name Then
DRow(8).Item = cName.Text
TMEventInfoParseGrid.DataS ource = dtForm
End If
Next
Found the solution with the help of a book.
Dim cName As TextBox = CType(sender, System.Windows.Forms.TextB
cName.Name = CType(sender, System.Windows.Forms.TextB
Dim DRow As DataRow
For Each DRow In dtForm.Rows
If DRow(2).Item = cName.Name Then
DRow(8).Item = cName.Text
TMEventInfoParseGrid.DataS
End If
Next
Found the solution with the help of a book.
ASKER
Sorry this one is correct
Dim cName As TextBox = CType(sender, System.Windows.Forms.TextB ox)
cName.Name = CType(sender, System.Windows.Forms.TextB ox).Name
Dim DRow As DataRow
For Each DRow In dtForm.Rows
If DRow.Item(2) = cName.Name.ToString Then
DRow.Item(8) = cName.Text
TMEventInfoParseGrid.DataS ource = dtForm
End If
Next
Dim cName As TextBox = CType(sender, System.Windows.Forms.TextB
cName.Name = CType(sender, System.Windows.Forms.TextB
Dim DRow As DataRow
For Each DRow In dtForm.Rows
If DRow.Item(2) = cName.Name.ToString Then
DRow.Item(8) = cName.Text
TMEventInfoParseGrid.DataS
End If
Next
For I as Integer = 0 to myarray.rows
if myarray.cells(I, KnownColumn) = KnownValue then Exit For
Next I
myarray.cells(I, KnownColumn + 2) = AlteredValue
Not too tough at all see :)