Cmd.executenonquery returns -1 in vb.net windows application

I simply insert an entry into the sqlserver database using a stored procedure. In this code, Binddata () is the method in which I recorded a gridview with the records.

here is the code:

Private Sub btnadd_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnadd.Click

    sqlSP = "INSERT_E_CLIENTMASTER_REC"
    strConnection = _
        ConfigurationManager.ConnectionStrings("connectstring").ConnectionString
    Dim conn As New SqlConnection(strConnection)

    conn.Open()

    Dim cmd As New SqlCommand(sqlSP, conn)

    cmd.CommandType = CommandType.StoredProcedure

    cmd.Parameters.Add(
        New SqlParameter("@CLIENTCODE", SqlDbType.VarChar, 100, _
            ParameterDirection.Input, False, 0, 0, "", _
            DataRowVersion.Proposed, txtclientcode.Text))
    'cmd.Parameters.Add( _
    '    New SqlParameter("@CLIENT_WEBXID", SqlDbType.NVarChar, _
    '        Convert.ToString(txtwebxid.Text))) _
    cmd.Parameters.Add( _
        New SqlParameter("@CLIENT_WEBXID", SqlDbType.VarChar, 100, _
            ParameterDirection.Input, False, 0, 0, "", _
            DataRowVersion.Proposed, txtwebxid.Text))

    cmd.Parameters.Add( _
        New SqlParameter("@ToEmail", SqlDbType.VarChar, 100, _
            ParameterDirection.Input, False, 0, 0, "", _
            DataRowVersion.Proposed, txttoemail.Text))

    cmd.Parameters.Add( _
        New SqlParameter("@ClientName", SqlDbType.VarChar, 100, _
        ParameterDirection.Input, _
        False, 0, 0, "", DataRowVersion.Proposed, txtclientname.Text))

    cmd.Parameters.Add(_
        New SqlParameter("@CcEmail", SqlDbType.VarChar, 100, _
        ParameterDirection.Input, False, 0, 0, "", _
        DataRowVersion.Proposed, txtccname.Text))

    Dim i As Int32 = cmd.ExecuteNonQuery()
    If (i < 0) Then
        BindData()
        MsgBox("Record Inserted successfully ", MsgBoxStyle.OkOnly)
        txtclientcode.Text = ""
        txtwebxid.Text = ""
        txttoemail.Text = ""
        txtclientname.Text = ""
        txtccname.Text = ""

    Else
        MsgBox("Record Not Inserted successfully ", MsgBoxStyle.OkOnly)
    End If

End Sub

In this code, cmd.ExecuteNonQuery () returns -1, so I gave (i <0) a condition, in fact it should be a positive value when the rows are affected.

Thanks in advance.

0
source share
2 answers

Is the record saved in the database? If so, then this is because the stored procedure does not return a value.

ExecuteNonQuery ()

UPDATE, INSERT DELETE , , . , , , , , . , -1. , -1. ​​

, fooobar.com/questions/1121127/...

. USING Block"

+1

"SET NOCOUNT ON"; SProc.

SET NOCOUNT (Transact-SQL): http://msdn.microsoft.com/en-us/library/ms189837.aspx

0

All Articles