[RESOLVED] Counting column values directly from Dataset Datatable.-VBForums
Results 1 to 3 of 3

Thread: [RESOLVED] Counting column values directly from Dataset Datatable.

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2013
    Posts
    58

    Resolved [RESOLVED] Counting column values directly from Dataset Datatable.

    Hello.
    I have a Data base with a table called Stock_Adjustment_Table and a column called STOCKRECORDNUMBER.
    I use the following code to count the number of times that the value datarowGOODS_RECEIPTS_DG.Item("STOCKRECORDNUMBER") appears in the STOCKRECORDNUMBER

    Code:
     Dim command7 As FbCommand = connection.CreateCommand()
                command7.Connection = connection
                command7.CommandText = "select count(*) from STOCK_ADJUSTMENT_TABLE where STOCKRECORDNUMBER = " & datarowGOODS_RECEIPTS_DG.Item("STOCKRECORDNUMBER")
    Now I also have the data base in a dataset called ds, with a table called STOCK_ADJUSTMENT_TABLE which has been filled with the code.

    Code:
      'fill the dataset/table with STOCK ADJUSTMENT TABLE  data
                daGOODS_RECEIPTS.SelectCommand.CommandText = "SELECT * FROM STOCK_ADJUSTMENT_TABLE "
                daGOODS_RECEIPTS.FillSchema(ds, SchemaType.Source, "STOCK_ADJUSTMENT_TABLE")
                daGOODS_RECEIPTS.Fill(ds, "STOCK_ADJUSTMENT_TABLE")
    My question, is there a way to count the information I want directly from the dataset table instead of the way I am doing at present by counting from the data base?

    Thank you.

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    3,348

    Re: Counting column values directly from Dataset Datatable.

    Here's an example,
    Code:
            Try
                Dim da As New OleDb.OleDbDataAdapter("select * from crops", My.Settings.WaterConnectionString)
                Dim dt As New DataTable
                da.Fill(dt)
                Dim num As Integer = dt.Compute("count([group])", "[group] = 'MELONS'")
                MessageBox.Show(num.ToString)
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2013
    Posts
    58

    Re: Counting column values directly from Dataset Datatable.

    Thank you wes4dbt. This was exactly what I was looking for. I have now worked that into my code and it is counting on the contents of the datatable rather than the contents of the database table.
    Code:
    Type = STOCK_ADJUSTMENT_TABLE.Compute("count(STOCKRECORDNUMBER)", "STOCKRECORDNUMBER = '" & datarowGOODS_RECEIPTS_DG.Item("STOCKRECORDNUMBER") & "'")
    ].

    Again thank you and could anyone suggest further reading on the subject of using datasets and related sql commands ?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.