D
Drygast
I have a form where I fetch some data in an accessdatabase. I would like to
present the result as 2 sets of data (I'm a newbie so I don't really know
how to express what I'm really looking for so bear with me). One set should
be sorted by "ordernumber" and the order set should be sorted by "date".
I understand this can be done through a sql-query "...order by odernumber",
but how do I type the code to execute 2 queries?
Here's the code I'm using:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Rensa fältet om det finns information
lblOrder2.Text = ""
lblIn2.Text = ""
lblUt2.Text = ""
lblAtgard2.Text = ""
lblSumma2.Text = ""
lblTotalSumma.Text = ""
oOrder = ""
oDagar = Nothing
oCount = Nothing
lbldagar.Text = ""
If chkMalmo.Checked = False And chkSkarholmen.Checked = False And
chkAnge.Checked = False Then
MsgBox("Du har glömt ange labb")
GoTo avsluta
Else
If chkMalmo.Checked = True Then
oLabb = "Malmö"
End If
If chkSkarholmen.Checked = True Then
oLabb = "Skärholmen"
End If
If chkAnge.Checked = True Then
oLabb = "Ånge"
End If
End If
'Hämta data
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Program Files\Smalfilm\smalfilm.mdb"
Dim cmd As New OleDbCommand("SELECT [Order].* FROM [Order] WHERE
Order.Status = 'Färdig' AND Order.Fakturerad = 0 AND Skickat_datum <= #" &
txtTo.Text & "# AND Labb = '" & oLabb & "' ORDER BY Order.Ordernummer", New
OleDbConnection(strConn))
cmd.Connection.Open()
Dim myReader As OleDbDataReader = cmd.ExecuteReader()
Try
While myReader.Read()
Dim TS As New TimeSpan
Dim NumDays As Integer
Dim StartDate
Dim EndDate
StartDate = myReader.GetDateTime(3)
EndDate = myReader.GetDateTime(6)
TS = EndDate.Subtract(StartDate)
NumDays = CInt(TS.TotalDays.ToString) + 1
lblOrder2.Text = lblOrder2.Text & myReader.GetValue(1) & vbCrLf
If oOrder = "" Then
oOrder = "'" & myReader.GetValue(1) & "'"
Else
oOrder = oOrder & " OR Ordernummer = '" & myReader.GetValue(1) & "'"
End If
lblIn2.Text = lblIn2.Text & myReader.GetDateTime(3).ToShortDateString &
vbCrLf
lblUt2.Text = lblUt2.Text & myReader.GetDateTime(6).ToShortDateString &
vbCrLf
lblAtgard2.Text = lblAtgard2.Text & myReader.GetValue(8) & vbCrLf
lblSumma2.Text = lblSumma2.Text & myReader.GetValue(14) & vbCrLf
lblTotalSumma.Text = Val(lblTotalSumma.Text.Replace(",", ".")) +
Val(myReader.GetValue(14).Replace(",", "."))
lbldagar.Text = lbldagar.Text & NumDays.ToString & vbCrLf
oDagar = oDagar + NumDays
oCount = oCount + 1
NumDays = Nothing
End While
Finally
myReader.Close()
cmd.Connection.Close()
End Try
Dim temp
If Not oDagar = Nothing Then
temp = oDagar / oCount
lblGenomsnitt.Text = temp
Else
lblGenomsnitt.Text = ""
End If
avsluta:
End Sub
Regards
/Drygast
present the result as 2 sets of data (I'm a newbie so I don't really know
how to express what I'm really looking for so bear with me). One set should
be sorted by "ordernumber" and the order set should be sorted by "date".
I understand this can be done through a sql-query "...order by odernumber",
but how do I type the code to execute 2 queries?
Here's the code I'm using:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Rensa fältet om det finns information
lblOrder2.Text = ""
lblIn2.Text = ""
lblUt2.Text = ""
lblAtgard2.Text = ""
lblSumma2.Text = ""
lblTotalSumma.Text = ""
oOrder = ""
oDagar = Nothing
oCount = Nothing
lbldagar.Text = ""
If chkMalmo.Checked = False And chkSkarholmen.Checked = False And
chkAnge.Checked = False Then
MsgBox("Du har glömt ange labb")
GoTo avsluta
Else
If chkMalmo.Checked = True Then
oLabb = "Malmö"
End If
If chkSkarholmen.Checked = True Then
oLabb = "Skärholmen"
End If
If chkAnge.Checked = True Then
oLabb = "Ånge"
End If
End If
'Hämta data
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Program Files\Smalfilm\smalfilm.mdb"
Dim cmd As New OleDbCommand("SELECT [Order].* FROM [Order] WHERE
Order.Status = 'Färdig' AND Order.Fakturerad = 0 AND Skickat_datum <= #" &
txtTo.Text & "# AND Labb = '" & oLabb & "' ORDER BY Order.Ordernummer", New
OleDbConnection(strConn))
cmd.Connection.Open()
Dim myReader As OleDbDataReader = cmd.ExecuteReader()
Try
While myReader.Read()
Dim TS As New TimeSpan
Dim NumDays As Integer
Dim StartDate
Dim EndDate
StartDate = myReader.GetDateTime(3)
EndDate = myReader.GetDateTime(6)
TS = EndDate.Subtract(StartDate)
NumDays = CInt(TS.TotalDays.ToString) + 1
lblOrder2.Text = lblOrder2.Text & myReader.GetValue(1) & vbCrLf
If oOrder = "" Then
oOrder = "'" & myReader.GetValue(1) & "'"
Else
oOrder = oOrder & " OR Ordernummer = '" & myReader.GetValue(1) & "'"
End If
lblIn2.Text = lblIn2.Text & myReader.GetDateTime(3).ToShortDateString &
vbCrLf
lblUt2.Text = lblUt2.Text & myReader.GetDateTime(6).ToShortDateString &
vbCrLf
lblAtgard2.Text = lblAtgard2.Text & myReader.GetValue(8) & vbCrLf
lblSumma2.Text = lblSumma2.Text & myReader.GetValue(14) & vbCrLf
lblTotalSumma.Text = Val(lblTotalSumma.Text.Replace(",", ".")) +
Val(myReader.GetValue(14).Replace(",", "."))
lbldagar.Text = lbldagar.Text & NumDays.ToString & vbCrLf
oDagar = oDagar + NumDays
oCount = oCount + 1
NumDays = Nothing
End While
Finally
myReader.Close()
cmd.Connection.Close()
End Try
Dim temp
If Not oDagar = Nothing Then
temp = oDagar / oCount
lblGenomsnitt.Text = temp
Else
lblGenomsnitt.Text = ""
End If
avsluta:
End Sub
Regards
/Drygast