I added a new table to our database named upc
.
When I add it to the front end of our site, I'm getting this error:
Description: An unhandled exception occurred during the execution of the current web 开发者_运维技巧request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: upc
Source Error:
if (!Sdr["upc"].ToString().Trim().Equals(""))
liupc.InnerHtml = "upc: " + Sdr["upc"].ToString();
else
I'm not sure what this error means or how I can resolve it - any insight is much appreciated.
I'm guessing (you really need to show more code) that "Sdr" is a SqlDataReader instance. If that's the case, you would not reference the table inside the indexer, but columns in the table (or whatever resultset) after a call to SqlCommand.ExecuteReader().
Something like:
SqlCommand cmd = ...;
SqlDataReader Sdr = cmd.ExecuteReader();
while(Sdr.Read())
{
var value = Sdr["column_name"];
// etc...
}
Also, see System.Data.SqlClient.SqlDataReader.
Simply put, it isn't recognizing "upc" as a string index in your array Sdr
.
change line 120 to be,
if(!string.IsNullOrEmpty(Sdr["upc"]))
and try that.
精彩评论