一个有关Update类型的存储过程的问题
生活随笔
收集整理的這篇文章主要介紹了
一个有关Update类型的存储过程的问题
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
CREATE PROCEDURE testupdateproc?? AS
declare @id int
declare @trandate datetime
declare @tranlimit int
update test set trandate=@trandate, tranlimit=@tranlimit where test.id=@id
GO
存儲過程語句如上,檢查語法是沒有問題的,但是在程序中執(zhí)行時卻不行。程序如下:
????????????Class1 c= new Class1();
????????????System.Data.SqlClient.SqlParameter[] para = new System.Data.SqlClient.SqlParameter[3];
??????????? para[0] = new System.Data.SqlClient.SqlParameter("@id",this.textBox3.Text);
???????????? if (this.textBox1.Text != "")
??????????????? para[1] = new System.Data.SqlClient.SqlParameter("@trandate", this.textBox1.Text);
??????????? else
??????????????? para[1] = new System.Data.SqlClient.SqlParameter("@trandate", DBNull.Value);
??????????? if (this.textBox2.Text != "")
??????????????? para[2] = new System.Data.SqlClient.SqlParameter("@tranlimit", this.textBox2.Text);
??????????? else
??????????????? para[2] = new System.Data.SqlClient.SqlParameter("@tranlimit", DBNull.Value);
??????????? //c.DataInsert();
??????????? if (c.DataUpdate())
??????????????? MessageBox.Show("OK");
??????????? else
??????????????? MessageBox.Show("False");
DataUpdae方法如下:
?????????public bool DataUpdate()
??????? {
??????????? string strConn = "Server=.;Initial Catalog=test;User Id=sa;Password=123";
??????????? SqlConnection sqlcon = new SqlConnection(strConn);
??????????? sqlcon.Open();
??????????? SqlCommand sqlcom = new SqlCommand();
??????????? sqlcom.Connection = sqlcon;
??????????? sqlcom.CommandType = CommandType.StoredProcedure;
??????????? sqlcom.CommandText = "testupdateproc";
??????????? int i = sqlcom.ExecuteNonQuery();
??????????? sqlcon.Close();
??????????? bool flag = false;
??????????? if (i > 0)
??????????????? flag = true;
??????????? else
??????????????? flag = false;
??????????? return flag;
??????? }
程序執(zhí)行返回的是false ,數(shù)據(jù)庫中數(shù)據(jù)也沒有改變,大家看看是怎么回事?
declare @id int
declare @trandate datetime
declare @tranlimit int
update test set trandate=@trandate, tranlimit=@tranlimit where test.id=@id
GO
存儲過程語句如上,檢查語法是沒有問題的,但是在程序中執(zhí)行時卻不行。程序如下:
????????????Class1 c= new Class1();
????????????System.Data.SqlClient.SqlParameter[] para = new System.Data.SqlClient.SqlParameter[3];
??????????? para[0] = new System.Data.SqlClient.SqlParameter("@id",this.textBox3.Text);
???????????? if (this.textBox1.Text != "")
??????????????? para[1] = new System.Data.SqlClient.SqlParameter("@trandate", this.textBox1.Text);
??????????? else
??????????????? para[1] = new System.Data.SqlClient.SqlParameter("@trandate", DBNull.Value);
??????????? if (this.textBox2.Text != "")
??????????????? para[2] = new System.Data.SqlClient.SqlParameter("@tranlimit", this.textBox2.Text);
??????????? else
??????????????? para[2] = new System.Data.SqlClient.SqlParameter("@tranlimit", DBNull.Value);
??????????? //c.DataInsert();
??????????? if (c.DataUpdate())
??????????????? MessageBox.Show("OK");
??????????? else
??????????????? MessageBox.Show("False");
DataUpdae方法如下:
?????????public bool DataUpdate()
??????? {
??????????? string strConn = "Server=.;Initial Catalog=test;User Id=sa;Password=123";
??????????? SqlConnection sqlcon = new SqlConnection(strConn);
??????????? sqlcon.Open();
??????????? SqlCommand sqlcom = new SqlCommand();
??????????? sqlcom.Connection = sqlcon;
??????????? sqlcom.CommandType = CommandType.StoredProcedure;
??????????? sqlcom.CommandText = "testupdateproc";
??????????? int i = sqlcom.ExecuteNonQuery();
??????????? sqlcon.Close();
??????????? bool flag = false;
??????????? if (i > 0)
??????????????? flag = true;
??????????? else
??????????????? flag = false;
??????????? return flag;
??????? }
程序執(zhí)行返回的是false ,數(shù)據(jù)庫中數(shù)據(jù)也沒有改變,大家看看是怎么回事?
轉(zhuǎn)載于:https://www.cnblogs.com/shunliy/archive/2008/04/03/1136049.html
總結(jié)
以上是生活随笔為你收集整理的一个有关Update类型的存储过程的问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 赶在世界末日前完成的2012年全年总结
- 下一篇: [转] 能ping通,但不能上网.