Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15496

Return the Index value of a datatable, by searching the Datatable

$
0
0
Hi everyone,

i'm ok with VB but some things are beyond me, and i don't know how to do the following.

I have a datagridview that displays a short filtered list from my datatable. my datatable is normally around 10,000 rows long.

i want to change one of the values in my "datagridviews cell" and then update that value in my datatable.

i have a function that will allow me to update my datatable row.
Code:

    ''' <summary>
    ''' Updates the data within the datatable
    ''' </summary>
    ''' <param name="TableName">Name of the table</param>
    ''' <param name="index">The index where the data will change</param>
    ''' <param name="value">Values that must match with this datatable</param>
    Public Sub UpdateDataInDataTable(TableName As String, index As Integer, value() As Object)
        Try
            Dim dt = ds.Tables(TableName)
            dt.Rows(index).ItemArray = value
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

as you can see this function needs to know the INDEX of which line in the original datatables collection of data to update.

i can't just use the index of the current row of my datagridview because it might only have say 5 rows and my datatable has 10,000 rows.

if it was possible to say "search" the datatable for the unique identifier in my datatable and then return what index row its on that would be great but i don't know how to do that.
my unique identifier is in a column called "Batch_Number". the unique identifier is typically a number like 0013205489 it has the double zeros at the start so i guess it would be treated like a string.

is anyone able to assist with this please?

Viewing all articles
Browse latest Browse all 15496

Trending Articles