索引超出了数组界限
string sqlBridge = string.Format("SELECT COUNT(DEVICEID) AS COUNT FROM DEVICE WHERE ORGID='{0}'", dataGridViewMain.Rows[index].Cells[0].Value.ToString());SqlCommand cmd = new SqlCommand(sqlBridge, con);
ArrayOfDeviceElement[] Bridge = new ArrayOfDeviceElement[length];
SqlDataReader sr = cmd.ExecuteReader();
sr.Read();
length = Convert.ToInt16(sr["COUNT"]);
sr.Close();
sqlBridge = string.Format("SELECT DEVICE.NAME AS NAME,DEVICE.DEVICEID AS DEVICEID,DEVICEPRODUCT.NAME AS TYPE FROM DEVICE,DEVICEPRODUCT WHERE DEVICE.PRODUCTID=DEVICEPRODUCT.PRODUCTID AND ORGID='{0}'", dataGridViewMain.Rows[index].Cells[0].Value.ToString());
cmd = new SqlCommand(sqlBridge, con);
sr = cmd.ExecuteReader();
while(sr.Read()&&++i<length)
{
try
{
Bridge[i].Name = sr["NAME"].ToString();
Bridge[i].CoordinateX += 100;
Bridge[i].CoordinateY += 100;
Bridge[i].DeviceId = sr["DEVICEID"].ToString();
Bridge[i].DeviceType = sr["TYPE"].ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
sr.Close();
问题在index上,index是点击dataview获取的 --------------------编程问答-------------------- dataGridView 好像有一个selectindex吧? 怎么不用那个! 还有就是你自己打印一下这个dataGridView的总行数 和你 的index比较一下 --------------------编程问答-------------------- 单步调试 --------------------编程问答-------------------- 调试,所有带 [] ,的地方特别注意
补充:.NET技术 , .NET Framework