I am very new to C# and just learning, I assume this is a pretty basic question but i need a bit of help.
I have a SQL join that I am putting in an object and passing to a viewModel but I seem to be having trouble when I change from select * to naming all the headers and assigning it to the object.
Select a.Desc,a.ID, b.Desc, b.state from a
join a ON b.Id = a.Id
using (SqlCommand cmd = new SqlCommand(query))
cmd.Connection = sqlCon;
using (SqlDataReader sdr = cmd.ExecuteReader())
Desc_a = sdr["a.Desc"].ToString(),
Desc_b = sdr["b.Desc"].ToString(),
id_a = Convert.ToInt32(sdr["a.Id"]),
State = sdr["b.state"].ToString()
I seem to be getting "System.IndexOutOfRangeException: a.Desc" error. I assume Im not assigning the value from the sql into the object correctly but im not seeing why?
Thank you for your help