You are on page 1of 1

string getdate = DateStart.Value.Date.ToString("MM/dd/yyyy 00:00:00.

000");
string getdateend = DateEnd.Value.Date.ToString("MM/dd/yyyy
23:59:59.999");

MessageBox.Show(getdate);
MessageBox.Show(getdateend);
try
{
DataSet ds = new DataSet();
if (connect.State != ConnectionState.Open)
connect.Open();
using (SqlDataAdapter da = new SqlDataAdapter(@"SELECT CAST(HDtime
AS DATE) AS TrongNgay, SUM(HDthanhtoan) AS TongTien FROM HoaDon" +
" WHERE HDtime BETWEEN '" + getdate + "' AND '" + getdateend + "' " +
" GROUP BY CAST(HDtime as DATE)", connect))
{
da.Fill(ds);
ChartMoneyDate.DataSource = ds;
//set the member of the chart data source used to data bind to
the X-values of the series
ChartMoneyDate.Series["MoneyDate"].XValueMember = "TrongNgay";
//set the member columns of the chart data source used to data
bind to the X-values of the series
ChartMoneyDate.Series["MoneyDate"].YValueMembers = "TongTien";
ChartMoneyDate.Titles.Add("Money Chart");
connect.Close();

}
connect.Close();
}
catch (Exception ex)
{
connect.Close();
MessageBox.Show(ex.Message);
}

Server=localhost;Database=master;Trusted_Connection=True;

You might also like