Out of range error on SqlDataReader

╄→尐↘猪︶ㄣ 提交于 2019-12-01 21:46:17

That's because you have no field named "record", you aliased it to "CUSTOMER_NO" so change the code to:

lblWebMasterMessage.Text += "record " + reader["CUSTOMER_NO"].ToString() + "<br />";

That said, you can also use index instead of name so to read the second column:

lblWebMasterMessage.Text += "record " + reader[1] + "<br />";

In my case this error was because I was accidentally executing two select statements in my command text. I had two separate output results and the first output didn't contain the column name I was reading and hence the error.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!