值未插入datasbase [英] Values are not inserting in datasbase

查看:118
本文介绍了值未插入datasbase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的存储过程当我尝试将数据插入表时它没有给出错误

当我执行ExecuteNonQuery时返回-1行受影响。

请告诉为什么数据没有插入表格。

 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();

解决方案

你需要设置



 selectBorroe_Crush_Data_OverDue.CommandType = CommandType.StoredProcedure; 





否则它认为SP名称是您正在执行的查询...



http://msdn.microsoft.com/en-us/library/system.data.commandtype.aspx [ ^ ]


这是代码用于调用storedprocedure。检查一下你是否错过了



 使用(SqlConnection con =  new  SqlConnection(dc.Con)){
使用(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();
}
}





谢谢

--RA

<试试这个:



  SET   NOCOUNT   OFF  





在你的SQL Server中有关更多信息,请参考这个 [ ^ ]。如果记录在数据库中但没有返回行数。



希望它有帮助:)


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.

 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();

解决方案

You need to set

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[^]


Here is the code for Calling storedprocedure. Check this for waht you have missed

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


Try this:

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 :)


这篇关于值未插入datasbase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆