TradingDAL.dll中出现未处理的“System.NullReferenceException”类型异常附加信息:对象引用未设置为对象的实例。 [英] An unhandled exception of type 'System.NullReferenceException' occurred in TradingDAL.dll Additional information: Object reference not set to an instance of an object.

查看:97
本文介绍了TradingDAL.dll中出现未处理的“System.NullReferenceException”类型异常附加信息:对象引用未设置为对象的实例。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码将值插入数据库。但它有一个soe错误

I m using the following code for insert values to the database. But Its have a soe error"

An unhandled exception of type 'System.NullReferenceException' occurred in TradingDAL.dll. Additional information: Object reference not set to an instance of an object."
I need to a help. please help me . Thanks in advance

dbConnection conn = new dbConnection();
       public int AddPurchase(IPurchase purchase)
       {
       string query = @"INSERT INTO purchase_account1 (posted_date, supplier_id, due_date, date_stamp, purchase_description, transaction_type,
                                               net_totalDiscount, net_purchase_total, net_total)VALUES  (@posted_date,@ supplier_name, @due_date, @date_stamp, @purchase_description,@transaction_type,@net_totalDiscount, @net_purchase_total, @net_total);SELECT purchase_id=SCOPE_IDENTITY()";

           SqlParameter[] parameter = new SqlParameter[9];

           parameter[0] = new SqlParameter("@posted_date", SqlDbType.Date);
           parameter[0]Value = ((DateTime)purchase.Posted).Date;

           parameter[1] = new SqlParameter("@supplier_name", SqlDbType.VarChar);
           parameter[1].Value =purchase.Supplier_Name.ToString() ;

           parameter[2] = new SqlParameter("@due_date", SqlDbType.Date);
           parameter[2].Value =((DateTime)purchase.DueDate).Date;

           parameter[3] = new SqlParameter("@date_stamp", SqlDbType.VarChar);
           parameter[3].Value = Convert.ToString(DateTime.Now);

           parameter[4] = new SqlParameter("@purchase_description", SqlDbType.VarChar);
           parameter[4].Value = purchase.Description.ToString();
          // string s = purchase.Description;
           parameter[5] = new SqlParameter("@transaction_type", SqlDbType.VarChar);
           parameter[5].Value = purchase.Transaction_type.ToString();

           parameter[6] = new SqlParameter("@net_totalDiscount", SqlDbType.Decimal);
           parameter[6].Value =((Decimal) purchase.Discount);

           parameter[7] = new SqlParameter("@net_purchase_total", SqlDbType.Decimal);
           parameter[7].Value = ((Decimal)purchase.Total);

           parameter[8] = new SqlParameter("@net_total", SqlDbType.Decimal);
           parameter[8].Value = ((Decimal)purchase.NetTotal);


           DataTable data = conn.executeSelectQuery(query, parameter);
           int purchaseid = Convert.ToInt32(data.Rows[0][0]);
           return purchaseid;
       }

推荐答案

正如评论中所提到的,这实际上是一个很容易修复的错误拥有。事实上,既然你没有告诉我们哪一行导致它,我们无论如何都无法确定如何修复它。只要查看导致错误的行,就会出现空值。只需解决这个问题就可以了。
As mentioned in the comments, this is actually a very easy error to fix on your own. In fact, since you did not tell us which line causes it we can't know for sure how to fix it anyway. Just look at the line that caused the error and something will be null. Just fix that and you're good.


这篇关于TradingDAL.dll中出现未处理的“System.NullReferenceException”类型异常附加信息:对象引用未设置为对象的实例。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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