当我尝试执行下面显示的SQL查询时,我得到一个IndexOutOfRangeException。我无法弄清楚为什么它在其他SO页面上说它可能是因为你试图从一个不存在的字段获取数据,但我确信它存在,并且当我将两个请求字段从“ ADRES“和”TAAL“改为”LEV“,就像上面那个只有2个底部的那个会拒绝工作,而对于”LEV“的最高要求仍然有效。 “ADRES”是8 LONG VARCHAR和“塔尔”是1个LONG VARCHAR场SQL索引超出范围例外
try
{
//BESTEL,[PLAN],LEV,ADRES,TAAL
SqlCommand getlist = new SqlCommand("select * from BESW where [email protected]", Connectie.connMEVO);
getlist.Parameters.Add("@best", SqlDbType.VarChar).Value = data.corrigeerbestnr;
DRorder = getlist.ExecuteReader();
while (DRorder.Read())
{
dateTimePicker1.Value = Convert.ToDateTime(DRorder["BESTEL"]);
dateTimePicker2.Value = Convert.ToDateTime(DRorder["PLAN"]);
comboBox1.Text = DRorder["LEV"].ToString();
comboBox2.Text = DRorder["ADRES"].ToString();
textBox8.Text = DRorder["TAAL"].ToString();
}
}
catch (Exception er) { MessageBox.Show("" + er); }
编辑:看来,如果我分裂了查询像图所示它的作品,我真的不明白这是为什么。
try
{
//BESTEL,[PLAN],LEV,ADRES,TAAL
SqlCommand getlist = new SqlCommand("select BESTEL,[PLAN],ADRES from BESW where [email protected]", Connectie.connMEVO);
getlist.Parameters.Add("@best", SqlDbType.VarChar).Value = data.corrigeerbestnr;
DRorder = getlist.ExecuteReader();
while (DRorder.Read())
{
dateTimePicker1.Value = Convert.ToDateTime(DRorder["BESTEL"]);
dateTimePicker2.Value = Convert.ToDateTime(DRorder["PLAN"]);
comboBox2.Text = DRorder["ADRES"].ToString();
}
SqlCommand getlist2 = new SqlCommand("select LEV from BESW where [email protected]", Connectie.connMEVO);
getlist2.Parameters.Add("@best", SqlDbType.VarChar).Value = data.corrigeerbestnr;
DRorder = getlist2.ExecuteReader();
while (DRorder.Read())
{
comboBox1.Text = DRorder["LEV"].ToString();
}
SqlCommand getlist3 = new SqlCommand("select TAAL from BESW where [email protected]", Connectie.connMEVO);
getlist3.Parameters.Add("@best", SqlDbType.VarChar).Value = data.corrigeerbestnr;
DRorder = getlist3.ExecuteReader();
while (DRorder.Read())
{
textBox8.Text = DRorder["TAAL"].ToString();
}
}
catch (Exception er) { MessageBox.Show("" + er); }
你调试了你的代码吗?在哪一行你会得到这个错误? – 2015-03-13 13:09:56
哪一行引发异常?该行使用的索引是什么?运行时该对象上可用的索引是什么? – David 2015-03-13 13:11:53
@大卫combobox1工作正常,但只要它到达combobox2它给出了错误,当我改变了顺序,所以combobox2是我注意到的查询的最后一个textbox8也给了这个错误。如果我把这两个作为评论查询将正常工作,我也试图设置他们使用“LEV”的字段,因为那一个为combobox1工作,但它仍然给这些错误2 – maam27 2015-03-13 13:12:13