PC Review


Reply
Thread Tools Rate Thread

InsertCommand generates code using sp_executesql

 
 
Vemund Haga
Guest
Posts: n/a
 
      17th Mar 2004
Hello,
I have a project where I am using a DataAdapter. A Command object is created
to use a stored procedure to insert data and the appropriate columns are
attached. The Command object is attached to the InsertCommand and the Update
method is called. So far, so good and the database receives SQL code to
execute sp_executesql. Here it stops with an error saying that there is a
syntax error.

Two questions:

1: Why does the DataAdapter use sp_executesql to do the insert? Previously I
have done the same in a VB.NET project and then the stored procedure has
been called directly. Now I am using C#. How to control whether the SP is
called directly or sp_executesql is used.

2: Why does the sp_executesql fail? The syntax is 'sp_executesql N'Command',
N'Parameter definition', N'Parameters''. I have tried to run the stored
procedure directly using the first and third part of the executesql and it
works. Ie. the stored procedure inserts data into the table. The parameter
definitions (second part) are the same as both the stored procedure
parameters and the table definition.

The sp_executesql works with sample code.


 
Reply With Quote
 
 
 
 
Vemund Haga
Guest
Posts: n/a
 
      17th Mar 2004
Sorry, found the answer myself just afterwards.

I forgot to set the CommandType property on the Command object to
CommandType.StoredProcedure.

Now it works like a charm.


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB Code generates error on another machine? =?Utf-8?B?UmljaGFyZCBTbW9saWsgKEtvcmRpYSk=?= Microsoft Excel Programming 4 9th Aug 2007 08:48 AM
Closing via Console generates non-zero exit code Peter Oliphant Microsoft VC .NET 1 23rd Nov 2005 03:22 AM
SQL code generates error message =?Utf-8?B?Si4gS2VnZ2VybG9yZA==?= Microsoft Access Form Coding 2 30th Dec 2004 06:03 PM
Visual Modeling that generates C# code Tim Conner Microsoft C# .NET 10 29th Oct 2003 05:08 PM
asp:form generates invalid code Vaclav Jedlicka Microsoft ASP .NET 6 23rd Jul 2003 04:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:13 PM.