别名怎么生效
string sql = string.Format("SELECT SUM(Statistical_number) AS Expr1,Statistical_data_Start FROM Statistical where Statistical_name='张三' GROUP BY Statistical_data_Start");
SqlCommand comm = new SqlCommand(sql, dbc.con);
SqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
dr = dt.NewRow();
dr["Expr1"] = (int)reader["Expr1"];
dr["Statistical_data_Start"] = (string)reader[1].ToString();
dt.Rows.Add(dr);
}
Expr1 怎么实现可以识别呢!
------解决方案--------------------
没看懂,给查询的列定义个名称 as NewColumnName 取或者绑定的时候直接用NewColumnName 新名称即可,还要怎么识别?
------解决方案--------------------
dr["Expr1"] = (int)reader["Expr1"];
是 dr["Expr1"]错误,不是后面的错误
你的Datatable里面没有定义Expr1列