Question generating profit loss statement from access database

Joined
Mar 24, 2012
Messages
7
Location
Mumbai, Maharashtra, India, India
Programming Experience
1-3
hello sir/mam
i want to generate a profit loss statement from access database i want to select transactions of a time interval by using the date time picker this is the code
Private Sub cmdGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGenerate.Click
Dim mycon7 As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\My Project\My Project\Stone Crusher\myproject.accdb")
mycon7.Open()
Dim cmd7 As New OleDb.OleDbCommand("select sum(total_price) from Transaction_table where Type='Buying' and Date_transaction between('" + DateTimePicker1.Text + "' and '" + DateTimePicker2.Text + "')", mycon7)
Dim i As Integer = cmd7.ExecuteScalar
mycon7.Close()
lblTotalBuying.Text = i
mycon7.Open()
Dim cmd As New OleDb.OleDbCommand("select sum(total_price) from Transaction_table where Type='Selling' and Date_transaction between('" + DateTimePicker1.Text + "' and '" + DateTimePicker2.Text + "')", mycon7)
Dim j As Integer = cmd.ExecuteScalar
mycon7.Close()
lblTotalSelling.Text = j
lblGrossAmount.Text = j - i


If j > i Then
lblStatusProfit.Visible = True
lblStatusProfit.Text = "You are in Profit"
Else
lblStatusLoss.Visible = True
lblStatusLoss.Text = "You are in Loss"
End If
End Sub
but i am getting a error message as
"Between operator without And in query expression 'Type='Buying' and Date_transaction between('3/24/2012' and '3/24/2012''."
at "Dim i As Integer = cmd7.ExecuteScalar"
and please also teach me how to make a chart on form of profit and loss
this is my form Image.JPG
 
Don't use string concatenation to insert values into SQL code. Always use parameters. To learn why and how, follow the Blog link in my signature and check out my post on Parameters In ADO.NET.
 
Back
Top