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
把 SET NOCOUNT ON; 注释掉。
EN 就是它...
有可能会出现负数,不知道什么原因,我也遇到过,在我的电脑出现,其他电脑都不会出现。