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]);
sda.SelectCommand = comm;
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
{
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);
sda.SelectCommand = comm;
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}