我有以下给出错误的代码cannot apply indexing with [] to an expression of type object
protected void btnMakeCards_Click(object sender, EventArgs e)
{
string cs = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
using (var con = new SqlConnection(cs))
using (var cmd = new SqlCommand("spDrugCardGenerator", con))
{
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach (var row in dt.Rows)
{
foreach (var col in dt.Columns)
{
Response.Write(row[col].ToString());
}
}
}
}
DataRow
如果我使用and的具体类型,为什么这段代码编译得很好DataColumn
?编译器可以在 using 语句中推断出数据类型应该是什么。数据表是怎么回事?