sydluce sydluce - 1 year ago 58
SQL Question

Why does my sql select not work?

I keep getting this exception:

No data exists for the row/column.

Yet the info in the select is correct. I don't know why this keeps failing.

string SQL = "SELECT htmlCodeBlock FROM HTML WHERE htmlID = 1";
command.CommandText = SQL;
command.Connection = conn;
reader = command.ExecuteReader();
codeBlock = reader["htmlCodeBlock"].ToString();

Tim Tim
Answer Source

It doesn't appear that you call Read() on the DataReader before trying to read data from it.

Retrieving Data Using a DataReader