如果没有在存储过程中输出参数获取错误,则Size属性的大小为0

时间:2015-02-12 08:51:45

标签: c# asp.net sql-server sql-server-2008 stored-procedures

我的存储过程

create PROCEDURE [dbo].[spAccDetailInsNew]
(
    @DocNo bigint,
    @DocType char(20),
    @DetailNo smallint,
    @AccountCode varchar(30),
    @FcAmount numeric(12,2),
    @FcCurrency varChar(30),
    @FcExchRate numeric(15,3),
    @Debit numeric(15,3),
    @Credit numeric(15,3),
    @Dc char(10),
    @DebitAdj numeric(15,3),
    @CreditAdj numeric(15,3),
    @Narration varchar(500),
    @FYear nvarchar(10),
    @DocDate smalldatetime)

我的asp.net代码是

cmd.Connection = Con;              
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "spAccDetailInsNew";

cmd.Parameters.Add("@DocNo", SqlDbType.BigInt).Value = _je.DocNo;
cmd.Parameters.Add("@DocType", SqlDbType.Char,20).Value = _je.DocType;
cmd.Parameters.Add("@DetailNo", SqlDbType.SmallInt,20).Value = _je.DetailNo;
cmd.Parameters.Add("@AccountCode", SqlDbType.NVarChar,30).Value = ddlAccName.SelectedValue;
cmd.Parameters.Add("@FCAmount",SqlDbType.Decimal).Value= Convert.ToDouble(s);
cmd.Parameters["@FCAmount"].Precision = 15;
cmd.Parameters["@FCAmount"].Scale = 3;
cmd.Parameters.Add("@FCCurrency", SqlDbType.VarChar,30).Value = ddlCurrency.SelectedItem.Text;
cmd.Parameters.Add("@FcExchRate",SqlDbType.Decimal).Value= ddlCurrency.SelectedValue;
cmd.Parameters.Add("@Debit",SqlDbType.Decimal).Value= string.IsNullOrEmpty(txtDebit.Text) ? 0 : Convert.ToDouble(txtDebit.Text);
cmd.Parameters.Add("@Credit",SqlDbType.Decimal).Value= string.IsNullOrEmpty(txtCredit.Text) ? 0 : Convert.ToDouble(txtCredit.Text);
cmd.Parameters.Add("@Dc",SqlDbType.Char,10).Value=dc;
cmd.Parameters.Add("@DebitAdj",SqlDbType.Decimal).Value= 0;
cmd.Parameters.Add("@CreditAdj",SqlDbType.Decimal).Value= 0;
cmd.Parameters.Add("@Narration", SqlDbType.VarChar,500).Value = txtGrdNarration.ToString();
cmd.Parameters.Add("@FYear", SqlDbType.NVarChar,10).Value = _je.FYear;
cmd.Parameters.AddWithValue("@DocDate", _je.DocDate);

Con.Open();
cmd.ExecuteNonQuery();
Con.Close();

i++;

1 个答案:

答案 0 :(得分:0)

删除@DetailNo

的大小
cmd.Parameters.Add("@DetailNo", SqlDbType.SmallInt,20).Value = _je.DetailNo;

应该是

cmd.Parameters.Add("@DetailNo", SqlDbType.SmallInt).Value = _je.DetailNo;