zoukankan      html  css  js  c++  java
  • 一个有关Update类型的存储过程的问题

    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 ,数据库中数据也没有改变,大家看看是怎么回事?
  • 相关阅读:
    Linux 安装 jdk 后 jps 出现问题/usr/jdk1.8.0_151/bin/jps: /lib/ld-linux.so.2: bad ELF interpreter: No such
    Jackson 注解
    Git 右键添加Git Bash
    No validator could be found for constraint
    rror querying database. Cause: java.sql.SQLException: null, message from server: "Host '192.168.30.1' is not allowed to connect to this MySQL server"
    Linux 安装 Mysql-5.7.23-linux-glibc2
    Promise
    PAT(B) 1094 谷歌的招聘(Java)
    PAT(B) 1074 宇宙无敌加法器(Java)
    PAT(B) 1078 字符串压缩与解压(Java)
  • 原文地址:https://www.cnblogs.com/shunliy/p/1136049.html
Copyright © 2011-2022 走看看