首页 新闻 会员 周边

为什么我的插入语句结果老是-1,但是却在表内成功插入了啊?

0
悬赏园豆:10 [已解决问题] 解决于 2013-08-15 11:51
private bool zydata(int tempid, string SendPhone, string text)
        {
            bool res = false;
            using (SqlConnection conn = new SqlConnection("Data Source=" + tb_ServiceIP2.Text + ";Initial Catalog=" + tb_Database2.Text + ";Persist Security Info=True;User ID=" + tb_User2.Text + ";Pwd=" + tb_Pwd2.Text + ""))
            {
                conn.Open();
                try
                {
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "zy_test_insert";
                    cmd.Connection = conn;

                    SqlParameter[] pas = new SqlParameter[2];
                    pas[0] = new SqlParameter("@SendPhone", SqlDbType.Text);
                    pas[1] = new SqlParameter("@text", SqlDbType.Text);
                    pas[0].Value = SendPhone;
                    pas[1].Value = text;
                    cmd.Parameters.Add(pas[0]);
                    cmd.Parameters.Add(pas[1]);



                    try
                    {
                        int i = 0;
                         i = cmd.ExecuteNonQuery();
                        if (i < 0)
                        {
                            tb_Showtext.AppendText("tempid=" + tempid + "转移数据出错");
                        }
                        else
                        {
                            res = true;
                        }
                    }
                    catch (Exception ex)
                    {

                        tb_Showtext.AppendText("tempid=" + tempid + "转移数据出错:" + ex.Message);
                    }

                }
                catch (Exception ex)
                {
                    tb_Showtext.AppendText("tempid=" + tempid + "转移数据出错:" + ex.Message);
                }
            }
            return res;
        }



----------------以下是存储过程----数据库内两个字段都是text类型的
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        <Author,,Name>
-- Create date: <Create Date,,>
-- Description:    <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[zy_test_insert]
(
@SendPhone text ,
@text text
)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

insert into UnhandlePhoneTable (SendPhone,text) values (@SendPhone,@text)


END
.F.的主页 .F. | 初学一级 | 园豆:13
提问于:2013-08-15 11:16
< >
分享
最佳答案
0

把 SET NOCOUNT ON; 注释掉。

收获园豆:10
Launcher | 高人七级 |园豆:45045 | 2013-08-15 11:23

EN   就是它...

.F. | 园豆:13 (初学一级) | 2013-08-15 11:51
其他回答(1)
0

有可能会出现负数,不知道什么原因,我也遇到过,在我的电脑出现,其他电脑都不会出现。

不懂cc | 园豆:877 (小虾三级) | 2013-08-15 11:20
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册