Solved

Finding which Row holds a certain string in one of it's cell in a datatable. VB.NET

Posted on 2006-06-16
8
240 Views
Last Modified: 2010-04-17
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.
0
Comment
Question by:JPERKS1985
  • 4
  • 4
8 Comments
 
LVL 20

Expert Comment

by:alainbryden
ID: 16925471
Unless it's a DOA, where you can do a query, just do the plain old loop

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 :)
0
 
LVL 20

Expert Comment

by:alainbryden
ID: 16925476
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
0
 
LVL 1

Author Comment

by:JPERKS1985
ID: 16925481
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
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 20

Expert Comment

by:alainbryden
ID: 16925544
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.
0
 
LVL 1

Author Comment

by:JPERKS1985
ID: 16927399
haah it is threaded.
0
 
LVL 20

Accepted Solution

by:
alainbryden earned 500 total points
ID: 16927656
Ahh I see, Well then I have no personal experience, but looking through this tutorial, it seems to give a pretty good outline of using the system data table.

http://smrtx.com/RS/asp_datagrid.htm
0
 
LVL 1

Author Comment

by:JPERKS1985
ID: 16928303
Created a solution


        Dim cName As TextBox = CType(sender, System.Windows.Forms.TextBox)
        cName.Name = CType(sender, System.Windows.Forms.TextBox).Name


        Dim DRow As DataRow
     
        For Each DRow In dtForm.Rows
            If DRow(2).Item = cName.Name Then
                DRow(8).Item = cName.Text
                TMEventInfoParseGrid.DataSource = dtForm
            End If
        Next

Found the solution with the help of a book.

0
 
LVL 1

Author Comment

by:JPERKS1985
ID: 16928325
Sorry this one is correct



     
        Dim cName As TextBox = CType(sender, System.Windows.Forms.TextBox)
        cName.Name = CType(sender, System.Windows.Forms.TextBox).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.DataSource = dtForm
            End If
        Next
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question