Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted
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?
Posted

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)

Posted

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()

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...