I have a table that has 14 rows in it that i want to return as well as declare each cell as a variable. Here is what I have tried:
using (SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["2012SSMS"].ConnectionString))
{
SqlCommand cmd1 = new SqlCommand(@"SELECT [Question], [Answer]
from [MyTable]", conn1);
conn1.Open();
using (SqlDataReader reader1 = cmd1.ExecuteReader())
{
while (reader1.HasRows)
{
reader1.GetName(0);
reader1.GetName(1);
while(reader1.Read())
{
string Question(1) = reader1.GetString(0); //errors here
string Answer(1) = reader1.GetString(1); //and here
}
reader1.NextResult();
}
}
}
my hope is to return the declared variables as Question1 - Question14 and Answer1 - Answer14. How do I go about doing this?