你好,我与LINQ一起使用存储过程,所以我可以获取SP的值,并使用IList方法将其显示在前端im上,这样它就可以循环并打印我调试的代码以及所有内容信息传递似乎很好,但是当我尝试保存我的值时不保存任何值,而是仅保存0,这是片段代码:
private static List<BusinessObject> ConnectToData()
{
SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["samvaConnectionString"].ConnectionString);//connectionString
DataSet dataSet = new DataSet("Data");
using (connection)
{
connection.Open();
SqlCommand cmd = new SqlCommand("spCliente_Proyectos_Gantt", connection);
cmd.CommandType = CommandType.StoredProcedure;
connection.Close();
cmd.Parameters.Clear();
connection.Open();
cmd.Parameters.AddWithValue("@idProyecto", 14);
//connection.Close();
SqlDataAdapter adapter = new SqlDataAdapter(cmd.CommandText, connection);
adapter.SelectCommand = cmd;
adapter.Fill(dataSet, "Data");
connection.Close();
}
IList<PropertyInfo> properties = typeof(BusinessObject).GetProperties().ToList();
List<BusinessObject> final = new List<BusinessObject>();
foreach (var row in dataSet.Tables[0].Rows)
{
BusinessObject guardar = CreateItemFromRow<BusinessObject>((DataRow)row, properties);
final.Add(guardar);
}
return final;
}
当我的代码到达“ final.Add(guardar);”行时最后是通过循环保存数据,而不是仅将rigth值保存为0,但是在ir到达该点行之前,值到达final之前,由于非常奇怪的原因,值已经获得了预期的值和行为。Add(guardar);它并没有保存任何关于为什么发生这种情况的任何想法?