-
Dec 4th, 2015, 04:13 PM
#1
Thread Starter
Lively Member
[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.
-
Dec 4th, 2015, 05:19 PM
#2
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
-
Dec 5th, 2015, 01:53 AM
#3
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|