sydluce sydluce - 6 months ago 11
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();
reader.Close();

Tim Tim
Answer

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

Retrieving Data Using a DataReader

Comments