torg Posted January 19, 2003 Posted January 19, 2003 I`ve got a DateTimePicker DtpDate dtpDate.CustomFormat = "dd.MM.yyyy" I`ve got an access database with a table table tblExpenses(amount, Date) tblExpenses.Date format format is DateTime (i.e : dd.mm.yyyy (11.01.2003)) I want to select sum(Amount) from tblExpenses where tblexpenses.date = dtpDate.value Dim Date As String = dtpDate.Value.Month Dim Expences As String = cboUtgift.Text adExpences= New OleDb.OleDbDataAdapter("SELECT Sum(tblExpences.Amount) AS 'Totals ' from tblExpences where '" & Date & "' = Month(tblExpences.Date) ", Me.OleDbConnection) adExpences.Fill(dsExpences, "dtExpences") Me.OleDbConnection.Close() What am I missing? give me a code example if possible Quote
torg Posted January 19, 2003 Author Posted January 19, 2003 Forgot to say: the code acts like the "WHERE" clause doesn`t work. As if the comparison isn`t a valid comparison. Anybody got an Idea about how to solve this problem? Quote
Moderators Robby Posted January 19, 2003 Moderators Posted January 19, 2003 You have it backwards, try this... "......from tblExpences where tblExpences.Date = #" & dtpDate.value & "#", Quote Visit...Bassic Software
torg Posted January 21, 2003 Author Posted January 21, 2003 I tried as you described, but received following message: "Syntax error in Date in query expression "tblExpences.Date = #19.01.2003"". tableExpemces.Date has Date/Time as Datatype, and short Date as format. dtpDate format is Short adInntekt = New OleDb.OleDbDataAdapter("select sum(tblExpences.Amount) as Tor FROM tblExpenceswhere tblExpences.date = #" & dtpDate.value & "# ", Me.OleDbConnection) Quote
Moderators Robby Posted January 21, 2003 Moderators Posted January 21, 2003 It may have a poblem with the field name Date, it's a reserved word. In that case use square brackets... .....Where [date] =.... Quote Visit...Bassic Software
torg Posted January 21, 2003 Author Posted January 21, 2003 I solved the problem by doing the following: Dim myString As String = dtpDato.Value Dim aString As String aString = (Replace(myString, ".", "/")) MessageBox.Show(aString) Try Me.OleDbConnection.Open() Dim Expences As String = cboExpences.Text adExpences= New OleDb.OleDbDataAdapter("select (tblExpences.Amount) as tot FROM tblExpences where tblExpences.date = #" & aString & "#;) ", Me.OleDbConnection) adExpences.Fill(dsExpences, "dtExpences") Me.OleDbConnection.Close() Quote
Moderators Robby Posted January 21, 2003 Moderators Posted January 21, 2003 Yeah, my fault, I forgot that dtpDato is returning a date type, so you could simply eliminate the pound (#) sign in you SQL string. Quote Visit...Bassic Software
Moderators Robby Posted January 21, 2003 Moderators Posted January 21, 2003 (edited) btw, it's preferable to use Replace from the .NET library... aString = myString.Replace(".","/") Edited January 21, 2003 by Robby Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.