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
存储过程语句如上,检查语法是没有问题的,但是在程序中执行时却不行。程序如下:
            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;
        }
程序执行返回的是false ,数据库中数据也没有改变,大家看看是怎么回事?
Tag标签: 我的问题

Feedback

#1楼 [楼主]   回复  引用  查看    

2008-04-11 23:15 by shunliy      
我的问题怎么没人解决啊,我实在是找不到原因

#2楼    回复  引用  查看    

2008-08-12 14:39 by 陈晨      
你的SqlCommand 和 SqlParameter[] 进行关联了吗?

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
Google站内搜索
[推荐职位]上海盛大网络招聘架构师



China-pub 计算机图书网上专卖店!6.5万品种 2-8折!
近千种 9-95 新二手计算图书火热销售中!
开发者征途系统新作:《设计模式——基于C#的工程化实现及扩展》

相关文章:


相关搜索:
我的问题

相关链接:
 

posts - 23, comments - 19, trackbacks - 0, articles - 1

Copyright © shunliy