Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my store procedure when i am trying to insert data into table its not giving error
when i execute ExecuteNonQuery its return -1 rows affected.
Please tell me why data is not inserting into table.
SQL
 selectBorroe_Crush_Data_OverDue.CommandText="INS_Borrow_Crush_Data";
                    
selectBorroe_Crush_Data_OverDue.Parameters.AddWithValue("@crush_id", crushid);
                    selectBorroe_Crush_Data_OverDue.Parameters.AddWithValue("@Borrow_Crush_DueType", strDueType);
                    
selectBorroe_Crush_Data_OverDue.Parameters.AddWithValue("@Borrow_TypeID", barroewtype);
                    selectBorroe_Crush_Data_OverDue.Parameters.AddWithValue("@Borrow_Crush_DueAmount", Convert.ToDecimal (txtGovtOverDue.Text));

                    selectBorroe_Crush_Data_OverDue.ExecuteNonQuery();
Posted
Updated 23-Jun-13 23:17pm
v2
Comments
Zoltán Zörgő 24-Jun-13 5:18am    
And what's in the INS_Borrow_Crush_Data?
ArunRajendra 24-Jun-13 5:19am    
Give a table structure?

You need to set

C#
selectBorroe_Crush_Data_OverDue.CommandType=CommandType.StoredProcedure;


Otherwise it thinks that the SP name is a query you're executing...

http://msdn.microsoft.com/en-us/library/system.data.commandtype.aspx[^]
 
Share this answer
 
Here is the code for Calling storedprocedure. Check this for waht you have missed

C#
using (SqlConnection con = new SqlConnection(dc.Con)) {
    using (SqlCommand cmd = new SqlCommand("sp_Add_contact", con)) {
      cmd.CommandType = CommandType.StoredProcedure;

      cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = txtFirstName.Text;
      cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = txtLastName.Text;

      con.Open();
      cmd.ExecuteNonQuery();
    }
  }


Thanks
--RA
 
Share this answer
 
Try this:

SQL
SET NOCOUNT OFF


in you SQL Server for more info refer this[^]. If the record is there in database but not returning the row count.

hope it helps :)
 
Share this answer
 
v4
command type is not defined..
C#
selectBorroe_Crush_Data_OverDue.CommandText="INS_Borrow_Crush_Data";
selectBorroe_Crush_Data_OverDue.CommandType=CommandType.StoredProcedure;                    
selectBorroe_Crush_Data_OverDue.Parameters.AddWithValue("@crush_id", crushid);
selectBorroe_Crush_Data_OverDue.Parameters.AddWithValue("@Borrow_Crush_DueType", strDueType);
selectBorroe_Crush_Data_OverDue.Parameters.AddWithValue("@Borrow_TypeID", barroewtype);
selectBorroe_Crush_Data_OverDue.Parameters.AddWithValue("@Borrow_Crush_DueAmount", Convert.ToDecimal (txtGovtOverDue.Text));
selectBorroe_Crush_Data_OverDue.ExecuteNonQuery();
 
Share this answer
 
Comments
Smanish87 24-Jun-13 7:07am    
i defined commandtype=storeprocedure
KiranKumar Roy 24-Jun-13 8:16am    
it worked???
Smanish87 24-Jun-13 9:27am    
thanks it works...
KiranKumar Roy 25-Jun-13 0:35am    
;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900