J
Justin
If I perform a simple select query in my project I'm able to fill my
gridview with no problem. However, once I wonder over to an aggregated
query were I sum two columns I run into tons of problems.
I also could never get this to work with a dataset. Since I only had one
table I opted to use only a datatable. Is that problematic?
Can someone help me out please?
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
Dim LineIn As String
Dim XQ
Dim LIN
Dim ZA
Dim StreamReader As System.IO.StreamReader
dt.Columns.Add(New Data.DataColumn("Date", GetType(Date)))
dt.Columns.Add(New Data.DataColumn("UPC", GetType(Int64)))
dt.Columns.Add(New Data.DataColumn("QTY_Sold", GetType(Integer)))
dt.Columns.Add(New Data.DataColumn("QTY_OnHand", GetType(Integer)))
dt.Columns.Add(New Data.DataColumn("Unit_Type", GetType(String)))
StreamReader = IO.File.OpenText("txt.txt")
While StreamReader.Peek <> -1
LineIn = StreamReader.ReadLine()
If Mid(LineIn, 1, 2) = "XQ" Then
XQ = Split(LineIn, "*")
ElseIf Mid(LineIn, 1, 3) = "LIN" Then
LIN = Split(LineIn, "*")
Else
ZA = Split(LineIn, "*")
dr = dt.NewRow()
dr("Date") = Mid(XQ(2), 5, 2) & "/" & Mid(XQ(2), 7, 2) & "/"
& Mid(XQ(2), 1, 4)
dr("UPC") = LIN(3)
dr("QTY_Sold") = "0"
dr("QTY_OnHand") = ZA(2)
dr("Unit_Type") = ZA(3)
dt.Rows.Add(dr)
End If
End While
StreamReader.Close()
'SELECT DATE, UPC, SUM(QTY_Sold), SUM(QTY_OnHand), Unit_Type FROM dt
Dim results As IEnumerable(Of DataRow) = Aggregate o In dt _
Group By UPC_Group =
o.Field(Of Int64)("UPC") _
Into test = Sum(o.Field(Of
Integer)("QTY_Sold")), test2 = Sum(o.Field(Of Integer)("QTY_OnHand"))
DataGridView1.DataSource = results.CopyToDataTable()
End Sub
End Class
gridview with no problem. However, once I wonder over to an aggregated
query were I sum two columns I run into tons of problems.
I also could never get this to work with a dataset. Since I only had one
table I opted to use only a datatable. Is that problematic?
Can someone help me out please?
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
Dim LineIn As String
Dim XQ
Dim LIN
Dim ZA
Dim StreamReader As System.IO.StreamReader
dt.Columns.Add(New Data.DataColumn("Date", GetType(Date)))
dt.Columns.Add(New Data.DataColumn("UPC", GetType(Int64)))
dt.Columns.Add(New Data.DataColumn("QTY_Sold", GetType(Integer)))
dt.Columns.Add(New Data.DataColumn("QTY_OnHand", GetType(Integer)))
dt.Columns.Add(New Data.DataColumn("Unit_Type", GetType(String)))
StreamReader = IO.File.OpenText("txt.txt")
While StreamReader.Peek <> -1
LineIn = StreamReader.ReadLine()
If Mid(LineIn, 1, 2) = "XQ" Then
XQ = Split(LineIn, "*")
ElseIf Mid(LineIn, 1, 3) = "LIN" Then
LIN = Split(LineIn, "*")
Else
ZA = Split(LineIn, "*")
dr = dt.NewRow()
dr("Date") = Mid(XQ(2), 5, 2) & "/" & Mid(XQ(2), 7, 2) & "/"
& Mid(XQ(2), 1, 4)
dr("UPC") = LIN(3)
dr("QTY_Sold") = "0"
dr("QTY_OnHand") = ZA(2)
dr("Unit_Type") = ZA(3)
dt.Rows.Add(dr)
End If
End While
StreamReader.Close()
'SELECT DATE, UPC, SUM(QTY_Sold), SUM(QTY_OnHand), Unit_Type FROM dt
Dim results As IEnumerable(Of DataRow) = Aggregate o In dt _
Group By UPC_Group =
o.Field(Of Int64)("UPC") _
Into test = Sum(o.Field(Of
Integer)("QTY_Sold")), test2 = Sum(o.Field(Of Integer)("QTY_OnHand"))
DataGridView1.DataSource = results.CopyToDataTable()
End Sub
End Class