public void abc()
{
string a = textBox1.Text.Trim() + "-" + textBox2.Text.Trim() + "-" + textBox3.Text.Trim() + " 20:00:00";
string b = textBox4.Text.Trim() + "-" + textBox5.Text.Trim() + "-" + textBox6.Text.Trim() + " 20:00:00";
try
{
if (DateTime.Parse(a) > DateTime.Parse(b))
{
MessageBox.Show("起始時間需早於終止時間");
return;
}
SqlConnection conn = new SqlConnection("server=10.19.1.59;database=mete_data;uid=sa;pwd=123");
//SqlConnection conn = new SqlConnection("server=.;database=mete_data;Trusted_Connection=yes");
conn.Open();
//調用預存程序
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "XCAllStation_BetweenTwoTime_SumRain";//預存程序的名字
comm.CommandType = CommandType.StoredProcedure;
IDataParameter[] parameters =
{
new SqlParameter("@strStartDatetime", SqlDbType.VarChar,30) , //預存程序中參數的名字
new SqlParameter("@strEndDatetime", SqlDbType.VarChar,30) //預存程序中參數的名字
};
//parameters[0].Value = "2012-7-6";
//parameters[1].Value = "2012-7-7";
parameters[0].Value = a;
parameters[1].Value = b;
comm.Parameters.Add(parameters[0]);
comm.Parameters.Add(parameters[1]);
////直接查詢
//SqlCommand comm = new SqlCommand("select * from RAIN_REALTIME",conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = comm;
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}