2 Replies - 344 Views - Last Post: 08 February 2018 - 02:37 AM Rate Topic: -----

#1 coos  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-February 18

Datetimepicker With VB.net

Posted 07 February 2018 - 11:39 PM

hi guys,

I am trying to extract data from mysql database using the below code but its not extracting anything. Kindly help.

            Dim startdate As Date = DateTimePicker1.Value.Date.ToString("yyyy-MM-dd")
            Dim enddate As Date = DateTimePicker2.Value.Date.ToString("yyyy-MM-dd")

            Dim cmd As OdbcCommand = New OdbcCommand("SELECT (productID) as Code,(unitPrice) as Amount,(totalSales) as Quantity,
             (sdate) as Date,(INV) as Invoice FROM sales WHERE sdate >= '" & startdate & "' And sdate <= '" & enddate & "' group by 
            productID order by INV ", cn)

            SampleDataAdapter.SelectCommand = cmd
            SampleDataAdapter.Fill(SampleSource)
            TableView = SampleSource.Tables(0).DefaultView
          


Is This A Good Question/Topic? 0
  • +

Replies To: Datetimepicker With VB.net

#2 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,526
  • Joined: 12-December 12

Re: Datetimepicker With VB.net

Posted 08 February 2018 - 02:32 AM

Is there an error message?

Build a string for your statement and then copy and execute its value in your MySQL control panel/front-end. I'm sure your statement is incorrect for use with GROUP BY.

Use parameterized queries anyway, which may resolve some issues, particularly related to date formatting. Your statement is not secure without parameters.

Note that Code and Date are reserved words in MySQL and it is preferable IMO to delimit them with back-ticks, or rename them (even though MySQL is tolerant of their use, particularly as aliases).
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,526
  • Joined: 12-December 12

Re: Datetimepicker With VB.net

Posted 08 February 2018 - 02:37 AM

(I thought ODBC was defunct, deprecated? As I recall.)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1