Hi,
I've got some weird behavior happening within one of the datamappers. It
all has to do with inserting a new row, and returning the Id of the row
being entered.
Here is what the code looks like that is getting "Object reference not set
to an instance ..." run-time error:
string ateId = cm.ExecuteScalar().ToString(); ß------------
this line crashes
None of the parameters are null, nor do they appear to have any illegal data
inside of them. The above code inserts a row into the AuditTrailEntry
table.
On the other hand, this code inserts a new jobStep row, and doesn't cause
any errors:
if (storedProcedure == "updateJobStep") //use this if update
cm.ExecuteNonQuery(); // no return value needed
else
{
string jobStepId = cm.ExecuteScalar().ToString(); //insert new
jobStep, get id of new row
js.Id = Convert.ToInt16(jobStepId);
}
Does anyone see a problem with this code, or know why it doesn't work?
TIA, Randy 2 5093
ExcuteScalar returns the first column value of the first row of the
first result set. if the first result set has no rows, this routine will
throw an error. would need the sp code to determine why the first result
set has no rows.
-- bruce (sqlwork.com)
Randy Smith wrote:
Hi,
I've got some weird behavior happening within one of the datamappers. It
all has to do with inserting a new row, and returning the Id of the row
being entered.
Here is what the code looks like that is getting "Object reference not set
to an instance ..." run-time error:
string ateId = cm.ExecuteScalar().ToString(); ß------------
this line crashes
None of the parameters are null, nor do they appear to have any illegal data
inside of them. The above code inserts a row into the AuditTrailEntry
table.
On the other hand, this code inserts a new jobStep row, and doesn't cause
any errors:
if (storedProcedure == "updateJobStep") //use this if update
cm.ExecuteNonQuery(); // no return value needed
else
{
string jobStepId = cm.ExecuteScalar().ToString(); //insert new
jobStep, get id of new row
js.Id = Convert.ToInt16(jobStepId);
}
Does anyone see a problem with this code, or know why it doesn't work?
TIA, Randy
Hi,
One of my coworker programmers solved the problem. The actual stored
procedure MUST return the value needed with code such as this:
SELECT SCOPE_IDENTITY() AS [AuditTrailEntriesId] //REPLACE
"AuditTrailEntriesId" with the name of the field you need to have returned
HTH, Randy
"bruce barker" <no****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
ExcuteScalar returns the first column value of the first row of the first
result set. if the first result set has no rows, this routine will throw
an error. would need the sp code to determine why the first result set has
no rows.
-- bruce (sqlwork.com)
Randy Smith wrote:
>Hi,
I've got some weird behavior happening within one of the datamappers. It all has to do with inserting a new row, and returning the Id of the row being entered. Here is what the code looks like that is getting "Object reference not set to an instance ..." run-time error:
string ateId = cm.ExecuteScalar().ToString(); ß------------ this line crashes
None of the parameters are null, nor do they appear to have any illegal data inside of them. The above code inserts a row into the AuditTrailEntry table. On the other hand, this code inserts a new jobStep row, and doesn't cause any errors:
if (storedProcedure == "updateJobStep") //use this if update
cm.ExecuteNonQuery(); // no return value needed
else
{
string jobStepId = cm.ExecuteScalar().ToString(); //insert new jobStep, get id of new row
js.Id = Convert.ToInt16(jobStepId);
} Does anyone see a problem with this code, or know why it doesn't work? TIA, Randy This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Shane |
last post by:
I've got a C# ASP.NET web form that fails to validate
under certain conditions. I have a radio button that
causes an AutoPostback that enables certain other elements
on the form. If I click that...
|
by: Marcin Vorbrodt |
last post by:
Hi there. How come when in one file i unclude <cmath> i need to use
std::tan(...), and in another file i include <cassert> and std::assert fails
to compile. Nowhere in my code i do using namespace...
|
by: Thomas |
last post by:
It looks like the String.replace doesn't work in IE6.1. Anyone else
has the same problem. I am using newest service package of IE and
Win2K.
Thanks
|
by: anon |
last post by:
How does the DataView.Sort method really work under the covers?
I know that it sorts a dataview, but what kind of sorting algorhythm is
actually used?
Thanks.
|
by: DavidGeorge |
last post by:
I'm having trouble with what seems like a very simple function,
although it's the first I've used in Access so I could have it all
mixed up. It still works fine in forms I designed until...
|
by: Dinesh |
last post by:
Hi,
I have one stored procedure in SQL server in which i have written one
insert statement. Now in my cs file i pass the parameters require to execute
that stored procedure and finaly by mistaken...
|
by: buran |
last post by:
Dear .NET Programmers,
I use the following code snippet but can't figure out what is going wrong
since the result object equals to nothing although it shouldn't be :)
Function...
|
by: ewolfman |
last post by:
Hi,
I'm trying to retrieve a private method using reflection, which exists
in my ASP.NET Page.
It works only if I change the method's accessor to 'protected'.
BTW: this occurs only for Page's...
|
by: mathewda |
last post by:
Hey, I'm having a problem that I consider kinda weird that is alluding
me at the moment. I've wrote some code that will set up an
XMLHttpRequest, it then makes a call to open and send and sets the...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| | |