这是我的第一个问题:SqlParameter已包含在另一个SqlParameterCollection中。SqlDataReader rdr[0]与object的比较为我带来了表列值。
public ArrayList[] GetInfo(string sqlCommand, SqlParameter sqlParameter)
{
ArrayList[] drawingInfo = new ArrayList[7];
drawingInfo[0] = new ArrayList();
drawingInfo[1] = new ArrayList();
drawingInfo[2] = new ArrayList();
drawingInfo[3] = new ArrayList();
drawingInfo[4] = new ArrayList();
drawingInfo[5] = new ArrayList();
drawingInfo[6] = new ArrayList();
using (SqlConnection con = new SqlConnection("connectionAdres"))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = sqlCommand;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(sqlParameter);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
drawingInfo[0].Add(rdr[0]);
drawingInfo[1].Add(rdr[1]);
drawingInfo[2].Add(rdr[2]);
drawingInfo[3].Add(rdr[3]);
drawingInfo[4].Add(rdr[4]);
drawingInfo[5].Add(rdr[5]);
drawingInfo[6].Add(rdr[6]);
}
return drawingInfo;
}
}
不能用同一对象作为参数两次调用GetInfo方法。只将值传递给该方法,然后每次重新生成SqlParameter。与使用SqlCommand相同。