I'm using a SqlDataReader and get this exception when trying to read a column...
System.IndexOutOfRangeException: record
Here is the code...
SqlCommand select = new SqlCommand("SELECT RTRIM(LTRIM(PART_NO)) AS PART_NO, record AS CUSTOMER_NO FROM [RMAData].[dbo].[IMPORTING_ORDER_EDI] WHERE sessionID = '" + Session.SessionID + "'", connection);
SqlDataReader reader = select.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
lblWebMasterMessage.Text += "record " + reader["record"].ToString() + "<br />";
...
If I change the lblWebMasterMessage.Text to the following it works just fine...
lblWebMasterMessage.Text += "record " + reader["PART_NO"].ToString() + "<br />";
The difference between record and PART_NO in the SQL Server table is that 'record' is a primary key and an int, PART_NO is a varchar(100).
The trouble is, I need the 'record' to identify the record to update it later...
I really can't see why it can return one field and not the other?
SQL Aliasingwhen ever you use theASkey word that's the field that you need to reference in your results set not the actual name that's in the Database itself