使用以下代码,我收到错误
位置0没有行。
protected void btnUpload_Click(object sender, EventArgs e)
{
DataTable dtExcel = new DataTable();
dtExcel.Clear();
if (Convert.ToInt32(dtExcel.Rows[0]["Mkey"]) > 0) // here is the error
{
Hid_Mode.Value = "M";
hid_mkey.Value = dtExcel.Rows[0]["Mkey"].ToString();
}
else
{
Hid_Mode.Value = "A";
hid_mkey.Value = "0";
}
答案 0 :(得分:1)
改变你的代码:
DataTable dtExcel = new DataTable();
dtExcel.Clear();
if (dtExcel.Rows.Count > 0) //Here's the change
{
Hid_Mode.Value = "M";
hid_mkey.Value = dtExcel.Rows[0]["Mkey"].ToString();
}
else
{
Hid_Mode.Value = "A";
hid_mkey.Value = "0";
}