日期:2014-05-18 浏览次数:20961 次
private void button1_Click(object sender, EventArgs e)
{
System.Data.DataTable dt = new System.Data.DataTable();
string strConn = "...你的连接字符串";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
try
{
System.Data.DataTable dt = new System.Data.DataTable();
getStrConn();
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
string strSql="select year(ShippedDate) as 年份,"
+"sum"
+" ("
+" case when "
+" month(ShippedDate) in (1,2,3)) "
+" then count(accid) as 销售总份数,sum(account) as 销售总金额 end"
+" else 0"
+" ) as 第一季度"
+"from EM where ShippedDate like'2010%'"
+"group by year(ShippedDate)"
+"order by year(ShippedDate)";
comm.CommandText = strSql;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = comm;
da.Fill(dt);
dataGridView1.DataSource = table;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "错误提示");
}
finally
{
conn.Close();
}
}