SqlCommand.CommandText

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

I'm trying to update a sql DB using the syntax below and I'm having no
luck.

myView.CommandText = "Exec usp_ins_EFTRecord " & SourceProgramID

The "Exec" works fine in query analyzer, and tests OK in enterprise,
but my code doesn't recognize it. In fact, I can substitute gibberish
for the Exec, and it blows past the command.

Thoughts?
 
If you wish to call a stored procedure from a sqlcommand object, you do
not need exec. You must set the text as the procedure name. Set the
command type appropriately and then add any parameters. Here's an
example. I have not compiled or tested but it should give you the
general idea.

System.Data.SqlClient.SqlCommand cmd = new
System.Data.SqlClient.SqlCommand();
cmd.CommandText = "usp_ins_EFTRecord";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@SourceProgramID", SqlDbType.Int);
cmd.Parameters[0].Value = 1;
 
Back
Top