Out of range error on SqlDataReader

前端 未结 2 956
礼貌的吻别
礼貌的吻别 2021-01-20 18:19

I\'m using a SqlDataReader and get this exception when trying to read a column...

System.IndexOutOfRangeException: record

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-20 18:57

    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() + "
    ";

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

    lblWebMasterMessage.Text += "record " + reader[1] + "
    ";

提交回复
热议问题