Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ExecuteScalar error 1

Status
Not open for further replies.

fdarkness

Programmer
Feb 17, 2006
110
CA
I'm tweaking and adjusting another programmer's ASP.NET application and this language is definitely not my forte. As a result, I'm totally lost on this error and I'm not sure how to fix it or even where to start.

In one of the pages when I attempt to save the information to the database, I get the following error:


Code:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

comm.CommandText = "SELECT " + field + " FROM Timesheet_AssignmentIDs";
keyNum = (Int32) comm.ExecuteScalar();


The line that starts with "keyNum" is highlighted as the line with the error (which I know isn't necessarily true, but it's what I have to start with right now).

This page worked before I did my tweaks and edits but doesn't know. My edits involved moving all the tables from one database to another, renaming most of them, and replacing some with my versions. Then I went through the code and made the .NET code refer to the new tables, fixed some of the column names and types in the replaced tables, and migrated a Stored Procedure over that I didn't know about until the app failed at one location.

I've managed to fix all the errors except for this one. I've checked to make sure the table names, column names and column types are correct (they are). Any help would be appreciated!
 
The ExecuteScalar method returns "The first column of the first row in the result set, or a null reference (Nothing in Visual Basic) if the result set is empty.".
So there are two possibilities:
1) The first column of the first row in the result set cannot be converted to Int32
2) The result set is empty.

Try to execute the SELECT against the database you're using and see what results you get.
 
Turns out the damn thing was empty. Didn't know it was supposed to have anything in it to begin! Nice of the previous developer to not think about putting that in his notes! *grr*.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top