ExecuteNonQuery and sp_executesql

D

David

Hello there,
I am having problems with a stored procedure. When a use SqlCommand,
SqlParameter and the ExecuteNonQuery method, i get this error:


Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'spSaveFormRequest'.

(1 row(s) affected)

The code in the Sql Profiler generated by the ExecuteNonQuery method is
as follows:

declare @P1 varchar(36)
set @P1=NULL
exec sp_executesql N'spSaveFormRequest',
N'@frmId varchar(36),@frmName varchar(32),@frmNameFra
varchar(32),@frmXmlConfigurationFile varchar(16),@frmInUse bit,@catId
varchar(36),@frmNewId varchar(36) output',
@frmId = '568a0a56-5559-4a6f-8023-89f7efea2696',
@frmName = 'Headsets replacement',
@frmNameFra = '',
@frmXmlConfigurationFile = NULL,
@frmInUse = 1,
@catId = '063da375-f39c-402d-b6a3-5a491360c99d', @frmNewId = @P1 output
select @P1

The c# code is


conn = new SqlConnection(this.connectionString);
command = new SqlCommand("spSaveFormRequest", conn);
conn.Open();

command.Parameters.Add("@frmId", SqlDbType.VarChar,
36).Value = frmId;
command.Parameters.Add("@frmName", SqlDbType.VarChar,
32).Value = frmName;
command.Parameters.Add("@frmNameFra", SqlDbType.VarChar,
32).Value = frmNameFra;
command.Parameters.Add("@frmXmlConfigurationFile",
SqlDbType.VarChar, 16).Value = xmlFile;
command.Parameters.Add("@frmInUse", SqlDbType.Bit).Value =
frmInUse;
command.Parameters.Add("@catId", SqlDbType.VarChar,
36).Value = catId;

SqlParameter frmNewId = new SqlParameter("@frmNewId",
SqlDbType.VarChar, 36);
frmNewId.Direction = ParameterDirection.Output;

command.Parameters.Add(frmNewId);

command.ExecuteNonQuery();

newid = command.Parameters["@frmNewId"].Value.ToString();

I am not sure what I am doing wrong.

Could someone perhaps help me with the error?
I am using Sql Server 2000, Framework 2.0

thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top