无法将参数值从String转换为十进制错误

时间:2016-09-17 14:02:50

标签: c# asp.net oracle stored-procedures

我想使用Storedprocedure.

将数据插入表格

我编写了如下代码

OracleConnection ObjPriCon = new OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["OracleConn"].ToString());
    ObjPriCon.Open();
    string spquery = "xxcus.pn_insert_grid_agreeement";
    OracleCommand cmd = new OracleCommand(spquery, ObjPriCon);
    cmd.CommandType = CommandType.StoredProcedure;

    cmd.Parameters.Add("Mkey", OracleType.Number).Value = e.Record["Mkey"];
    cmd.Parameters.Add("GrdType", OracleType.VarChar).Value = e.Record["grd_type"];
    cmd.Parameters.Add("firstname", OracleType.VarChar).Value = e.Record["f_name"];
    cmd.Parameters.Add("lastname", OracleType.VarChar).Value = e.Record["l_name"];

    cmd.Parameters.Add("contactdet", OracleType.Number).Value = e.Record["cont_det"];
    cmd.Parameters.Add("pancardDet", OracleType.VarChar).Value = e.Record["pancard_det"];
    cmd.Parameters.Add("trantype", OracleType.VarChar).Value = "GDS";
    cmd.Parameters.Add("createdby", OracleType.Number).Value = Request.QueryString["userid"].ToString();

    cmd.Parameters.Add("creationdate", OracleType.DateTime).Value = DateTime.Now.ToString("dd/MM/yyyy");
    cmd.Parameters.Add("lastUpdateDate", OracleType.DateTime).Value = DateTime.Now.ToString("dd/MM/yyyy");
    cmd.Parameters.Add("lastUpdatedBy", OracleType.Number).Value = Request.QueryString["userid"].ToString();
    cmd.Parameters.Add("deleteflag", OracleType.Char).Value = "N";

    cmd.ExecuteNonQuery();
    ObjPriCon.Close();

但在cmd.ExecuteNonQuery()我收到错误

  

无法将参数值从String转换为Decimal。

我不明白错误在哪里

另见我的SP结构

CREATE OR REPLACE PROCEDURE XXCUS.pn_insert_grid_agreeement (
       mkey               NUMBER,  
       GrdType           VARCHAR2,
       firstname             VARCHAR2,
       lastname             VARCHAR2,
       contactdet           NUMBER,
       pancardDet        VARCHAR2,
       trantype          VARCHAR2,
       createdby         NUMBER,
       creationdate      DATE,
       lastUpdateDate   DATE,
       lastUpdatedBy    NUMBER,
       deleteflag        CHAR
    )
    IS
    BEGIN
       INSERT INTO xxcus.xxacl_pn_grid_agreement
                   (MKEY, grd_type, f_name, l_name, cont_det, pancard_det, tran_type,
                    created_by, creation_date, last_update_date,
                    last_updated_by, delete_flag
                   )
            VALUES (mkey, GrdType, firstname,lastname, contactdet,pancardDet, trantype,
                    createdby, creationdate, lastUpdateDate,
                    lastUpdatedBy, deleteflag
                   );
    END;

请建议这里有什么问题

UDPATE

Mkey是自动递增列。

1 个答案:

答案 0 :(得分:1)

尝试更换:

cmd.Parameters.Add("createdby", OracleType.Number).Value = Request.QueryString["userid"].ToString();
cmd.Parameters.Add("lastUpdatedBy", OracleType.Number).Value = Request.QueryString["userid"].ToString();

使用:

cmd.Parameters.Add("lastUpdatedBy", OracleType.Number).Value = Convert.ToInt32(Request.QueryString["userid"]);
cmd.Parameters.Add("createdby", OracleType.Number).Value = Convert.ToInt32(Request.QueryString["userid"]);