Click here to Skip to main content
15,895,667 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Using VB.NET 2005 With MySQL Pin
EliottA3-Sep-09 5:15
EliottA3-Sep-09 5:15 
AnswerRe: Using VB.NET 2005 With MySQL Pin
εїзεїзεїз3-Sep-09 6:50
εїзεїзεїз3-Sep-09 6:50 
QuestionNeed help with SQL query Pin
sazd13-Sep-09 1:53
sazd13-Sep-09 1:53 
AnswerRe: Need help with SQL query Pin
Johan Hakkesteegt3-Sep-09 2:31
Johan Hakkesteegt3-Sep-09 2:31 
AnswerRe: Need help with SQL query Pin
dan!sh 3-Sep-09 3:34
professional dan!sh 3-Sep-09 3:34 
GeneralRe: Need help with SQL query Pin
sazd13-Sep-09 3:38
sazd13-Sep-09 3:38 
AnswerRe: Need help with SQL query Pin
Pasan1483-Sep-09 5:04
Pasan1483-Sep-09 5:04 
GeneralRe: Need help with SQL query Pin
sazd13-Sep-09 8:39
sazd13-Sep-09 8:39 
I tried something like this to have balance of stock at any date or interval between two dates

Dim cmdText As String = "SELECT pt.ItemId, pt.Description, SUM(pt.Quantity)AS QuantityPurchased, SUM(st.Quantity) AS QuantitySold, (SUM(pt.Quantity) - SUM(st.Quantity)) AS Balance FROM PurchaseTable pt INNER JOIN SalesTable st ON pt.ItemId=st.ItemId WHERE pt.PDate Between @START and @END GROUP BY pt.ItemId, pt.Description"

If con.State = ConnectionState.Closed Then con.Open()
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(cmdText, con)
cmd.CommandType = CommandType.Text

cmd.Parameters.AddWithValue("@START", OleDb.OleDbType.Date).Value = TextBox1.Text
cmd.Parameters.AddWithValue("@END", OleDb.OleDbType.Date).Value = TextBox2.Text

Dim dr As OleDb.OleDbDataReader

If con.State = ConnectionState.Closed Then con.Open()
dr = cmd.ExecuteReader
If Not dr.HasRows Then
MessageBox.Show("No Records Found for Date: " & TextBox1.Text)
Else
MessageBox.Show("Record found for Date: " & TextBox1.Text)
ListView1.Items.Clear()
ListView1.ForeColor = Color.DarkRed
ListView1.GridLines = True

While dr.Read
Dim ls As New ListViewItem(dr.Item("ItemId").ToString())
ls.SubItems.Add(dr.Item("Description").ToString())
ls.SubItems.Add(dr.Item("QuantityPurchased").ToStr ing())
ls.SubItems.Add(dr.Item("QuantitySold").ToString() )
ls.SubItems.Add(dr.Item("Balance").ToString())
ListView1.Items.Add(ls)
End While
End If
But i could not get the desired results. Please advise what i am doing wrong with this.

The problem i am having is as under:
Data in PurchaseTable

PId PDate ItemId Description Price Quantity Amount
1 28/8/2009 1 Coca Cola Normal 1,00 10 10,00
2 28/8/2009 2 Coca Cola Zero 1,00 5 5,00
3 29/8/2009 1 Coca Cola Normal 1,00 5 5,00
4 29/8/2009 2 Coca Cola Zero 1,00 10 10,00

Data in Sales Table is as under:

SId SDate ItemId Description Price Quantity Amount
1 30/8/2009 1 Coca Cola Normal 2,70 2 5,40
2 30/8/2009 2 Coca Cola Zero 2,70 3 7,10
3 31/8/2009 1 Coca Cola Normal 2,70 1 2,70
4 31/8/2009 2 Coca Cola Zero 2,70 2 2,70

The result of query with date range of 28-08-2009 to 29-08-2009 and also with the date range of 28-08-2009 to 31-08-2009 is displayed as under:

Coca Cola Normal 30 6 24
Coca Cola Zero 30 10 20

whereas actually for date range of 28-08-2009 to 29-08-2009 the result should be as under:

Coca Cola Normal 15 0 15
Coca Cola Zero 15 0 15

And with the date range of 28-08-2009 to 31-08-2009 the result should be as under:

Coca Cola Normal 15 3 12
Coca Cola Zero 15 5 10

Pleae advise what i am doing wrong with the query.
Thanks again for your guidance.
QuestionTimer set time click Pin
Bob Beaubien2-Sep-09 21:52
Bob Beaubien2-Sep-09 21:52 
AnswerRe: Timer set time click Pin
TheComputerMan2-Sep-09 22:13
TheComputerMan2-Sep-09 22:13 
AnswerRe: Timer set time click Pin
David Skelly2-Sep-09 22:57
David Skelly2-Sep-09 22:57 
AnswerRe: Timer set time click Pin
Johan Hakkesteegt3-Sep-09 0:32
Johan Hakkesteegt3-Sep-09 0:32 
GeneralRe: Timer set time click Pin
Bob Beaubien3-Sep-09 2:49
Bob Beaubien3-Sep-09 2:49 
GeneralRe: Timer set time click Pin
Johan Hakkesteegt3-Sep-09 3:31
Johan Hakkesteegt3-Sep-09 3:31 
GeneralRe: Timer set time click Pin
Bob Beaubien3-Sep-09 3:40
Bob Beaubien3-Sep-09 3:40 
GeneralRe: Timer set time click [modified] Pin
Bob Beaubien3-Sep-09 15:15
Bob Beaubien3-Sep-09 15:15 
GeneralRe: Timer set time click Pin
Johan Hakkesteegt3-Sep-09 20:12
Johan Hakkesteegt3-Sep-09 20:12 
GeneralRe: Timer set time click [modified] Pin
Bob Beaubien4-Sep-09 4:32
Bob Beaubien4-Sep-09 4:32 
GeneralRe: Timer set time click Pin
Johan Hakkesteegt6-Sep-09 20:05
Johan Hakkesteegt6-Sep-09 20:05 
GeneralRe: Timer set time click Pin
TheComputerMan4-Sep-09 9:59
TheComputerMan4-Sep-09 9:59 
GeneralRe: Timer set time click Pin
Bob Beaubien5-Sep-09 2:39
Bob Beaubien5-Sep-09 2:39 
AnswerRe: Timer set time click Pin
Ashfield3-Sep-09 1:34
Ashfield3-Sep-09 1:34 
GeneralRe: Timer set time click Pin
Bob Beaubien3-Sep-09 2:50
Bob Beaubien3-Sep-09 2:50 
GeneralRe: Timer set time click Pin
Ashfield3-Sep-09 3:33
Ashfield3-Sep-09 3:33 
Questioninsert excel worksheet also apply the excel formula in vb.net Pin
newdbo2-Sep-09 21:30
newdbo2-Sep-09 21:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.