project execute successfully, but when i click on purchase or sales option of my project then project suddenly crashes and error occurs.i want to save all the the transection entered through save button into the database. i'm new in c# so please help
transectionsDAL tdal = new transectionsDAL();
transectionDetailDAL tdDAL = new transectionDetailDAL();
using(TransactionScope scope=new TransactionScope())
{
int transactionID = -1;
bool w = tdal.Insert_Transection(transection,out transactionID);
for(int i = 0; i < transectiondt.Rows.Count; i++)
{
transectionDetailBLL transactiondetail = new transectionDetailBLL();
string productname = transectiondt.Rows[i][0].ToString();
productsBLL p = pdal.GetproductIDFromName(productname);
transactiondetail.product_id = p.id;
transactiondetail.rate = decimal.Parse(transectiondt.Rows[i][1].ToString());
transactiondetail.qty = decimal.Parse(transectiondt.Rows[i][2].ToString());
transactiondetail.total = Math.Round(decimal.Parse(transectiondt.Rows[i][3].ToString()),2);
transactiondetail.dea_cust_id = dc.id;
transactiondetail.added_date = DateTime.Now;
transactiondetail.dea_cust_id = u.id;
bool y = tdDAL.InsertTransectionDetail(transactiondetail);
success = w && y;
At first check the documentation: https://learn.microsoft.com/en-us/do.net/api/system.typeinitializationexception?view.netcore-3.1
The exception that is thrown as a wrapper around the exception thrown by the class initializer.
That means it's either one of the deals
transectionsDAL tdal = new transectionsDAL();
transectionDetailDAL tdDAL = new transectionDetailDAL();
Or the bll
transectionDetailBLL transactiondetail = new transectionDetailBLL();
It could also be inside one of your functions
To get to the real problem, you need to inspect the real reason which is in the InnerException
field.
When a class initializer fails to initialize a type, a TypeInitializationException is created and passed a reference to the exception thrown by the type's class initializer. The InnerException property of TypeInitializationException holds the underlying exception.
My suggestion for you to get the real exception would be to wrap with
try {
/// your code here
}
catch (TypeInitializationException e) {
throw e.InnerException;
}
Even better, debug your code line by line to see where the problem is.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.