Index was outside the bounds of the array error, TextBox7.Text = dr[1].ToString();
Index was outside the bounds of the array error, TextBox7.Text = dr[1].ToString();
我不明白这个错误,我是 c# 的新手,这是我第一次看到这个错误,你能帮我出出主意吗?
cn.Open();
SqlCommand Cmd = new SqlCommand("select EmerPacienti from Outpacient WHERE PacientId ='" +
DropDownList1.SelectedValue + "'", cn);
SqlDataReader dr = Cmd.ExecuteReader();
if (dr.Read())
{
TextBox4.Text = dr[0].ToString();
TextBox7.Text = dr[1].ToString();
}
dr.Close();
cn.Close();
您的查询仅 returns 单列 (EmerPacienti
),但您引用了第二列 (dr[1]
)。
我不明白这个错误,我是 c# 的新手,这是我第一次看到这个错误,你能帮我出出主意吗?
cn.Open();
SqlCommand Cmd = new SqlCommand("select EmerPacienti from Outpacient WHERE PacientId ='" +
DropDownList1.SelectedValue + "'", cn);
SqlDataReader dr = Cmd.ExecuteReader();
if (dr.Read())
{
TextBox4.Text = dr[0].ToString();
TextBox7.Text = dr[1].ToString();
}
dr.Close();
cn.Close();
您的查询仅 returns 单列 (EmerPacienti
),但您引用了第二列 (dr[1]
)。