I try to read all the fields of a column (second column -link-) in my database. I find this example, but I can't manage to read one column of varchar type:
SQLConnection.Open();
using (SqlCommand command = new SqlCommand("SELECT link FROM shop", SQLConnection))
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine("{2}",reader.GetString(2));
}
}
I've got this error:
Index was outside the bounds of the array.
and I don't understand why...
Thanks in advance :)
SELECT * FROM shop, cause you're getting the second column withreader.GetString(2)