类文件错误插入语句有很多参数 [英] class file error insert statement has to many argument

查看:87
本文介绍了类文件错误插入语句有很多参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个与建筑商应用程序相关的项目....我制作了一个有关水泥数据的网页.........现在我已经显示了所有这些文件..
1)aspx.cs文件...

i have making one projects related to builders application....in that i have made one web page for cement data .........now i have showing all this files..
1)aspx.cs file......

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace astha_developers
{
    public partial class cementdata : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                loaddatatogrid();
            }
        }
        protected void loaddatatogrid()
        {
            GridView1.DataSource = cement_class.select();
            GridView1.DataBind();
        }

        protected void btnsave_Click(object sender, EventArgs e)
        {

            cement_class c = new cement_class();
            c.brandname = Convert.ToString(txtbrandname.Text);

            c.suppliername = Convert.ToString(txtsuppname.Text);
            c.cementorderdate = Convert.ToDateTime(txtorderdate.Text);

            c.numberofbags = Convert.ToInt16(txtnoofbags.Text);

            c.rateperbag = Convert.ToDouble(txtrate.Text);

            c.amount = Convert.ToDouble(txtamount.Text);
            c.recievedate = Convert.ToDateTime(txtrecieveddate.Text);

            c.noofbagrecieved = Convert.ToInt16(txtrecievedbags.Text);
            c.openingstock = Convert.ToInt16(txtopeningstock.Text);

            c.usedstock = Convert.ToInt16(txtusedstock.Text);
            c.closedstock = Convert.ToInt16(txtclosingstock.Text);





            int result = c.insert();
            loaddatatogrid();
            clearall();
        }

        protected void btnedit_Click(object sender, EventArgs e)
        {
            cement_class c = new cement_class();
            c.brandname = Convert.ToString(txtbrandname.Text);

            c.suppliername = Convert.ToString(txtsuppname.Text);
            c.cementorderdate = Convert.ToDateTime(txtorderdate.Text);

            c.numberofbags = Convert.ToInt16(txtnoofbags.Text);

            c.rateperbag = Convert.ToDouble(txtrate.Text);

            c.amount = Convert.ToDouble(txtamount.Text);
            c.recievedate = Convert.ToDateTime(txtrecieveddate.Text);

            c.noofbagrecieved = Convert.ToInt16(txtrecievedbags.Text);
            c.openingstock = Convert.ToInt16(txtopeningstock.Text);

            c.usedstock = Convert.ToInt16(txtusedstock.Text);
            c.closedstock = Convert.ToInt16(txtclosingstock.Text);





            int result = c.update(Convert.ToInt32(txtid.Text));
            loaddatatogrid();
            clearall();
        }

        protected void btndelete_Click(object sender, EventArgs e)
        {
            cement_class c = new cement_class();
            c.delete(Convert.ToInt32(txtid.Text));
            loaddatatogrid();
            clearall();
        }

        protected void btnreset_Click(object sender, EventArgs e)
        {

            clearall();

        }
        protected void clearall()
        {
            txtid.Text = "";
            txtbrandname.Text = "";
            txtsuppname.Text = "";
            txtorderdate.Text = "";
            txtnoofbags.Text = "";
            txtrate.Text = "";
            txtamount.Text = "";
            txtrecieveddate.Text = "";
            txtrecievedbags.Text = "";
            txtopeningstock.Text = "";
            txtusedstock.Text = "";
            txtclosingstock.Text = "";
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int i = GridView1.SelectedRow.RowIndex;
            txtid.Text = GridView1.Rows[i].Cells[1].Text;
            txtbrandname.Text = GridView1.Rows[i].Cells[2].Text;
            txtsuppname.Text = GridView1.Rows[i].Cells[3].Text;

            txtorderdate.Text = GridView1.Rows[i].Cells[4].Text;
            txtnoofbags.Text = GridView1.Rows[i].Cells[5].Text;
            txtrate.Text = GridView1.Rows[i].Cells[6].Text;

            txtamount.Text = GridView1.Rows[i].Cells[7].Text;
            txtrecieveddate.Text = GridView1.Rows[i].Cells[8].Text;
            txtrecievedbags.Text = GridView1.Rows[i].Cells[9].Text;
            txtopeningstock.Text = GridView1.Rows[i].Cells[10].Text;
            txtusedstock.Text = GridView1.Rows[i].Cells[11].Text;
            txtclosingstock.Text = GridView1.Rows[i].Cells[12].Text;
        }
    }
}




2)class文件.....




2)class file.....

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;

namespace astha_developers
{
    public class cement_class
    {
        private int _cid = 0;
        private string _brandname = "";
        private string _suppliername = "";
        private DateTime _cementorderdate;
        private int _numerofbags = 0;
        private double _rateperbag = 0;
        private double _amount = 0;
        private DateTime _recieveddate;
        private int _noofbagrecieved = 0;
        private int _openingstock = 0;
        private int _usedstock = 0;
        private int _closedstock = 0;
        public int cid
    {
          get
        {
            return _cid;
        }
        set
        {
            _cid = value;
        }

    }
    public string brandname
    {
        get
        {
            return _brandname;
        }
        set
        {
            _brandname = value;
        }
    }

    public string suppliername
    {
        get
        {
            return _suppliername;
        }
        set
        {
            _suppliername = value;
        }
    }
    public DateTime cementorderdate
    {
        get
        {
            return _cementorderdate;
        }
        set
        {
            _cementorderdate = value;
        }

    }


    public int numberofbags
    {
        get
        {
            return _numerofbags;
        }
        set
        {
            _numerofbags = value;
        }
    }

    public double rateperbag
    {
        get
        {
            return _rateperbag;
        }
        set
        {
            _rateperbag = value;
        }

    }


    public double amount
    {
        get
        {
            return _amount;
        }
        set
        {
            _amount = value;
        }
    }
    public DateTime recievedate
    {
        get
        {
            return _recieveddate;
        }
        set
        {
            _recieveddate = value;
        }

    }


    public int noofbagrecieved
    {
        get
        {
            return _noofbagrecieved;
        }
        set
        {
            _noofbagrecieved = value;
        }
    }

    public int openingstock
    {
        get
        {
            return _openingstock;
        }
        set
        {
            _openingstock = value;
        }

    }


    public int usedstock
    {
        get
        {
            return _usedstock;
        }
        set
        {
            _usedstock = value;
        }
    }
    public int closedstock
    {
        get
        {
            return _closedstock;
        }
        set
        {
            _closedstock = value;
        }

    }
    public int insert()
    {
        SqlParameter[] param = new SqlParameter[12];
        //param[0] = new SqlParameter("@cid", SqlDbType.Int);
        //param[0].Value = _cid;
        param[0] = new SqlParameter("@brandname", SqlDbType.VarChar);
        param[0].Value = _brandname;

        param[1] = new SqlParameter("@mode", SqlDbType.VarChar);
        param[1].Value = "insert";
        param[2] = new SqlParameter("@suppliername", SqlDbType.VarChar);
        param[2].Value = _suppliername;
        param[3] = new SqlParameter("@cementorderdate", SqlDbType.DateTime);
        param[3].Value = _cementorderdate;

        param[4] = new SqlParameter("@numberofbags ", SqlDbType.Int);
        param[4].Value = _numerofbags;
        param[5] = new SqlParameter("@rateperbag ", SqlDbType.Float);
        param[5].Value =_rateperbag;
        param[6] = new SqlParameter("@amount ", SqlDbType.Float);
        param[6].Value = _amount;

        param[7] = new SqlParameter("@recievedate", SqlDbType.DateTime);
        param[7].Value = _recieveddate;
        param[8] = new SqlParameter("@noofbagrecieved ", SqlDbType.Int);
        param[8].Value = _noofbagrecieved;
        param[9] = new SqlParameter("@openingstock ", SqlDbType.Int);
        param[9].Value = _openingstock;


        param[10] = new SqlParameter("@usedstock ", SqlDbType.Int);
        param[10].Value = _usedstock;

        param[11] = new SqlParameter("@closedstock ", SqlDbType.Int);
        param[11].Value = _closedstock;

        
        int result = astha_developers.commondata.ExecuteStatement("insertcement", CommandType.StoredProcedure, param);
        return result;

    }
         public int update(int id)
    {

        SqlParameter[] param = new SqlParameter[13];
        param[0] = new SqlParameter("@cid", SqlDbType.Int);
        param[0].Value = _cid;
        param[1] = new SqlParameter("@brandname", SqlDbType.VarChar);
        param[1].Value = _brandname;

        param[2] = new SqlParameter("@mode", SqlDbType.VarChar);
        param[2].Value = "insert";
        param[3] = new SqlParameter("@suppliername", SqlDbType.VarChar);
        param[3].Value = _suppliername;
        param[4] = new SqlParameter("@cementorderdate", SqlDbType.DateTime);
        param[4].Value = _cementorderdate;

        param[5] = new SqlParameter("@numberofbags ", SqlDbType.Int);
        param[5].Value = _numerofbags;
        param[6] = new SqlParameter("@rateperbag ", SqlDbType.Float);
        param[6].Value = _rateperbag;
        param[7] = new SqlParameter("@amount ", SqlDbType.Float);
        param[7].Value = _amount;

        param[8] = new SqlParameter("@recievedate", SqlDbType.DateTime);
        param[8].Value = _recieveddate;
        param[9] = new SqlParameter("@noofbagrecieved ", SqlDbType.Int);
        param[9].Value = _noofbagrecieved;
        param[10] = new SqlParameter("@openingstock ", SqlDbType.Int);
        param[10].Value = _openingstock;


        param[11] = new SqlParameter("@usedstock ", SqlDbType.Int);
        param[11].Value = _usedstock;

        param[12] = new SqlParameter("@closedstock ", SqlDbType.Int);
        param[12].Value = _closedstock;


        int result = astha_developers.commondata.ExecuteStatement("updatecement", CommandType.StoredProcedure, param);
        return result;

    }
         public void delete(int id)
         {
             SqlParameter[] param = new SqlParameter[2];
             param[0] = new SqlParameter("@cid", SqlDbType.Int);
             param[0].Value = _cid;
             param[1] = new SqlParameter("@mode", SqlDbType.VarChar);
             param[1].Value = "delete";
             int result =astha_developers.commondata.ExecuteStatement("deletecement", CommandType.StoredProcedure, param);
             

         }
         public static DataTable select()
         {
             SqlParameter[] param = new SqlParameter[1];
             param[0] = new SqlParameter("@mode", SqlDbType.VarChar);
             param[0].Value = "select";

             DataTable dt = astha_developers.commondata.GetDataTable("selctcement", CommandType.StoredProcedure, param);
             return dt;
         }


        
    }
}



3)用于与数据库连接的类文件.



3)class file for connection with database..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;

namespace astha_developers
{
    public class commondata
    {
        public static string Connstr = ConfigurationManager.ConnectionStrings["astha_developers"].ToString();
        public static int ExecuteStatement(String command, CommandType cmdType, SqlParameter[] parameters)
        {
            SqlConnection Conn = new SqlConnection();
            try
            {
                Conn = new SqlConnection(Connstr);
                Conn.Open();
                int result = -1;
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = cmdType;
                cmd.CommandText = command;
                cmd.Connection = Conn;

                if (parameters != null)
                {
                    foreach (SqlParameter param in parameters)
                    {
                        cmd.Parameters.Add(param);
                    }
                }
                result = Int32.Parse(cmd.ExecuteNonQuery().ToString());

                Conn.Close();
                return result;
            }
            catch (Exception ex)
            {
                if (Conn.State == ConnectionState.Open)
                {
                    Conn.Close();
                }
                throw new Exception(ex.Message);
            }
        }
        public static DataTable GetDataTable(String command, CommandType cmdType, SqlParameter[] parameters)
        {
            SqlConnection Conn = new SqlConnection();
            try
            {
                Conn = new SqlConnection(Connstr);
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = cmdType;
                cmd.CommandText = command;
                cmd.Connection = Conn;


                //if (parameters != null)
                //{
                //    foreach (SqlParameter param in parameters)
                //    {
                //        cmd.Parameters.Add(param);
                //    }
                //}

                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataSet ds = new DataSet();
                da.Fill(ds);
                Conn.Close();

                if (ds.Tables[0].Rows.Count > 0)
                {
                    return ds.Tables[0];
                }
                else
                {
                    return null;
                }

            }
            catch (Exception ex)
            {
                if (Conn.State == ConnectionState.Open)
                {
                    Conn.Close();
                }
                throw new Exception(ex.Message);
            }
        }
    }
}


和存储过程....用于插入数据..


and store procedures....for inserting the data ..

ALTER procedure [dbo].[insertcement] @brandname varchar(50),@suppliername varchar(50),@cementorderdate datetime,@noofbags int,@rateperbag float,@amount float,@recieveddate datetime,@nofbagsrecieved int,@openingstock int,@usedstock int,@closedstock int
 as
insert into cementdetails(brandname,suppliername,cementorderdate ,noofbags ,rateperbag ,amount ,recieveddate,noofbagsrecieved ,openingstock ,usedstock ,closedstock) values(@brandname,@suppliername,@cementorderdate ,@noofbags ,@rateperbag ,@amount ,@recieveddate,@nofbagsrecieved ,@openingstock ,@usedstock ,@closedstock)


但这给我显示了类似..
的错误


but it shows me error like..

Procedure or function insertcement has too many arguments specified...


所以帮我找出来并成功插入数据...
谢谢..


so help me to find it out and succesfully insert the data...
thankss..

推荐答案

这是一个巨大的代码转储.该错误表示它的意思.您提供了太多的论点.以后,请阅读错误消息,如果需要帮助,请在代码块中张贴有错误的代码,告诉我们哪一行会给您错误,并解释为什么您这样简单地认为是给您的原因英语的问题,是错误的.我们无法告诉您哪个呼叫中断了,因为我们没有存储的proc的代码.
This is a massive code dump. The error means what it says. You''re providing too many arguments. In future, read the error message, and if you need to ask for help, post JUST the block of code with the error, tell us what line gives you the error, and also explain why you think that the reason given to you in plain English for the problem, is wrong. We can''t tell you which call is broken b/c we don''t have the code of the stored procs.


这篇关于类文件错误插入语句有很多参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆