Re: ExecuteNonQuery() returns -1

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



According to the MSDN documentation, ExecuteNonQuery() only returns the rows
affected for INSERT, DELETE and UPDATE statements. Any other statement
(presumably including calls to a stored proc) will return -1.

Quote:
"For UPDATE, INSERT, and DELETE statements, the return value is the number
of rows affected by the command. For all other types of statements, the
return value is -1. If a rollback occurs, the return value is also -1."


<gallian@xxxxxxxxx> wrote in message
news:1151543097.504639.321760@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I am trying to insert new records in table via stored proc
EMP_Calendar_SAVE_sp. There is no exception thorwn but RowsAffected is
-1. I have tested the store proc, it works fine. Any Help?



Code as below:=
Public Sub EMP_Calendar_SAVE_sp(ByVal EmployeeCode As String, ByVal
CalendarType As String, ByVal StartDate As Date, ByVal EndDate As Date)
Dim SelectCommandText As String = "EMP_Calendar_SAVE_sp"
Dim MySqlCommand As New SqlCommand(cmdText:=SelectCommandText,
connection:=MyBase.m_Connection, transaction:=MyBase.m_Transaction)
MySqlCommand.CommandType = CommandType.StoredProcedure

MySqlCommand.Parameters.Add(New SqlParameter("@EmployeeCode",
EmployeeCode))
MySqlCommand.Parameters.Add(New SqlParameter("@CalendarType",
CalendarType))
MySqlCommand.Parameters.Add(New SqlParameter("@StartDate",
StartDate))
MySqlCommand.Parameters.Add(New SqlParameter("@EndDate",
EndDate))

Dim RowsAffected As Integer
Try
RowsAffected = MySqlCommand.ExecuteNonQuery()
Catch ex As Exception
Dim Message As String = "Error calling stored procedure '"
+ SelectCommandText + "'" + Environment.NewLine _
+ "EmployeeCode='" + EmployeeCode +
"'" + Environment.NewLine _
+ "CalenderType='" + CalendarType +
"'" + Environment.NewLine _
+ "StartDate='" + StartDate + "'" +
Environment.NewLine _
+ "EndDate='" + EndDate
Throw New Exception(Message)
End Try
End Sub



.



Relevant Pages

  • ExecuteNonQuery() returns -1
    ... I am trying to insert new records in table via stored proc ... There is no exception thorwn but RowsAffected is ... CalendarType As String, ByVal StartDate As Date, ByVal EndDate As Date) ... Dim RowsAffected As Integer ...
    (microsoft.public.dotnet.framework.adonet)
  • Simple stored pro example for vb.net 2
    ... A stored proc is called which returns one value- all in code and cannot ... Public Function ReturnStoredProcedure(ByVal sStoredProcedure As String, ... Dim MyConnection As SqlConnection ... Dim dblTemp As Double ...
    (microsoft.public.dotnet.languages.vb)
  • RE: getting return value from stored proc
    ... stored proc that scans 4 tables for the 2 parameters passed in from the front ... The same with the dimSQL ... Dim nondimSQL As String ...
    (microsoft.public.access.formscoding)
  • Re: DATAGRID QUESTION
    ... Dim x as string = request.querystring ... Select...Case statement to determine what stored proc. ... > I'm trying to build a datagrid by taking a parameter in the query ...
    (microsoft.public.dotnet.framework.aspnet.datagridcontrol)
  • Re: Getting stored procedure result to excel
    ... here's the answer to how to get results of a stored proc. ... Dim vParams As Variant ... End Sub ... Dim rsReturn As ADODB.Recordset ...
    (microsoft.public.excel.programming)