Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I converted the date to dd-MM-yyyy and saved these dates in the database having column of type <strong>varchar</strong></p> </blockquote> <p>No offense but this is terribly wrong. There is no reason to use <code>varchar</code> as column type for your date values. Use <code>DATE</code> or <code>DATETIME</code> column types instead. That's what they for.</p> <ul> <li><a href="http://www.tutorialspoint.com/mysql/mysql-data-types.htm" rel="nofollow">MySQL Data Types</a></li> </ul> <p>In your case, I suggest you to use <code>DATE</code> column type because it supports <code>YYYY-MM-DD</code> format.</p> <p>And you should always use <em><a href="http://www.codinghorror.com/blog/2005/04/give-me-parameterized-sql-or-give-me-death.html" rel="nofollow">parameterized queries</a></em>. This kind of string manipulations are open for <em><a href="http://en.wikipedia.org/wiki/SQL_injection" rel="nofollow">SQL Injection</a></em> attacks.</p> <pre><code>string dateFrom = dtp_dfrom.Value.ToString("YYYY-MM-DD"); string dateTo = dtp_dto.Value.ToString("YYYY-MM-DD"); using(MySqlConnection conn = new MySqlConnection(myconstring)) { DataTable dt = new DataTable(); using(MySqlCommand cmd = new MySqlCommand("SELECT trans_date, product_type AS Item, product_quantity, amount, SUM( product_quantity ) AS Qty, SUM( amount ) AS 'Total Price' FROM main_table WHERE trans_date BETWEEN @dateFrom AND @dateTo GROUP BY product_type")) { cmd.Parameters.AddWithValue("@dateFrom", dateFrom); cmd.Parameters.AddWithValue("@dateTo", dateTo); MySqlDataAdapter sda = new MySqlDataAdapter(cmd, conn); sda.Fill(dt); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload