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 5044
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: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
| | |