Stored Procedure

  • Thread starter Thread starter Catalin Porancea
  • Start date Start date
C

Catalin Porancea

Hello,

How can I execute a stored procedure through a odbc command? My stored
procedure only modifies data in db, it doesn't returns any rows and doesn't
use any parameter.

Thank you
 
I did, but I got an error saying:

The command text is invalid. To call a stored procedure through ODBC managed
provider the following syntax should be used:

{ CALL <stored procedure name> ( <parameter list> ) }

--
Catalin Porancea
: You can use ExecuteNonQuery method on your connection object.
:
: : > Hello,
: >
: > How can I execute a stored procedure through a odbc command? My stored
: > procedure only modifies data in db, it doesn't returns any rows and
: doesn't
: > use any parameter.
: >
: > Thank you
: >
: >
: >
: > --
: > Catalin Porancea
: >
: >
:
:
 
Catalin Porancea said:
How can I execute a stored procedure through a odbc command? My
stored procedure only modifies data in db, it doesn't returns any
rows and doesn't use any parameter.

This is a VB.NET language group. Please turn to
microsoft.public.dotnet.framework.adonet.
 
ok, if I want to execute the command as a select statement I only have to
use

cmd.commandtext = "select * from table"
cmd.executenonquery

I tried to use
cmd.commandtext = "exec sp_procedure"
cmd.executenonquery

but I get an error.

Does anybody have a solution instead of sending me from one group to
another. Arm, my question is exactly about VB .Net.

--
Catalin Porancea
: Hello,
:
: How can I execute a stored procedure through a odbc command? My stored
: procedure only modifies data in db, it doesn't returns any rows and
doesn't
: use any parameter.
:
: Thank you
:
:
:
: --
: Catalin Porancea
:
:
 
Does anybody have a solution instead of sending me from one group to
another. Arm, my question is exactly about VB .Net.
I agree with Armin that your question would probably recieve a quicker
response in the ADO.Net newsgroup, but here is an answer.

Be sure to set the command type to StoredProcedure. Here is an example:


'Code starts here
Dim strCN As String = ConfigurationSettings.AppSettings("Northwind_DSN")
Dim cn As New SqlConnection(strCN)
Dim cmd As New SqlCommand

cn.Open()

With cmd
.Connection = cn
.CommandType = CommandType.StoredProcedure
.CommandText = "usp_region_save"
.Parameters.Add("@id", mintRegionId)
.Parameters.Add("@region", mstrRegionDescription)
.ExecuteNonQuery()
End With

cmd = Nothing
cn.Close()
 
Back
Top