过程或函数 'StoredProcedure1' 需要参数 '@starttime',但未提供该参数。
string connectionString = @"Server=lcf; database=XSBOOK;Integrated Security=True";
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand myCommand = new SqlCommand("StoredProcedure1", con);
//调用存储过程名
myCommand.CommandType = CommandType.StoredProcedure;
//设置存储过程的参数值,其中@id 为存储过程的参数.
SqlParameter id1 = myCommand.Parameters.Add("@starttime", SqlDbType.DateTime);
id1.Direction = ParameterDirection.Input;
id1.SqlValue = "2012-05-30";
SqlParameter id2 = myCommand.Parameters.Add("@endtime", SqlDbType.DateTime);
id2.Direction = ParameterDirection.Input;
id2.SqlValue = "2013-06-20";
//SqlParameter[] spr = new SqlParameter[2];
//spr[0] = new SqlParameter("@starttime", "2012-05-30");
//spr[1] = new SqlParameter("@endtime", "2013-06-20");
//myCommand.Parameters.Add(spr[0]);
//myCommand.Parameters.Add(spr[1]);
//myCommand.ExecuteNonQuery();
//执行命令
//SqlDataReader reader = myCommand.ExecuteReader();//读取数据
string nn = "StoredProcedure1";
SqlDataAdapter da = new SqlDataAdapter(nn, con);
DataSet ds = new DataSet();
da.Fill(ds, "XS");
bindingSource1.DataSource = ds;
bindingSource1.DataMember = "XS";
//bindingSource1.Sort = "sno desc";
dataGridView1.DataSource = bindingSource1;