I am having an issue with the below error saying that there is no data present for the second read item (bold and underlined).
But I can see in the data that both fields have data in them. any ideas why the approver2 variable is not being populated?
Thanks in advance.
Error
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll Additional information: Invalid attempt to read when no data is present.
C#
string approver = null; string approver2 = null; con.Open(); string Approve = "Select Approver"+ ",Approver2"+ " From dbo.Tbl_Overview"+ " Where RequestID = '" + STAR.Globals.Detail + STAR.Globals.DetailNum + "'"; using (SqlCommand command = new SqlCommand(Approve, con)) { SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) approver = reader["Approver"] as string; [u][b]approver2 = reader["Approver2"] as string;[/b][/u] } } con.Close();
SQL
Select Approver,Approver2 From dbo.Tbl_Overview Where RequestID = 'CR4'
Results
Approver Approver2 User.1 User2