NAVEEN KUMAR

NAVEEN KUMAR

  • NA
  • 81
  • 6.6k

I want to send datatable value from one page to 2nd in asp.net c#

Jul 19 2020 11:58 PM
I have a web project in which a 'Cart.aspx page'. In this page i stored datatable value in session variable like below:
 
" Session["Buyitem"]=dt; . Now i want to use this session variable value in second page 'PaymentGateway.aspx' page like below:
  1. DataTable dt;  
  2. dt = (DataTable)Session["Buyitem"];  
  3. for (int i = 0; i <= dt.Rows.Count - 1; i++)  
  4. {  
  5. con = new SqlConnection(cons);  
  6. con.Open();  
  7. string sql = ("Insert into OrderDetails(OrderID,ProductName,ProductImage,Price,CustomerName,BillingAddress,OrderDate,OrderStatus)values('" + Session["OrderID"] + "','" + dt.Rows[i]["Product_Name"] + "','" + dt.Rows[i]["ProdImage"] + "','" + dt.Rows[i]["ProdPrice"] + "','" + Session["CstmrName"] + "','" + Session["BillingAddress"] + "','" + Session["Orderdate"] + "','Pending')");  
  8. cmd = new SqlCommand(sql, con);  
  9. cmd.ExecuteNonQuery();  
  10. con.Close();  
  11. Session["Buyitem"] = null;  
  12. }  
but i am getting "System.NullReferenceException: 'Object reference not set to an instance of an object.'
dt was null."
 
Now i want to clear something:
 
By Cart.aspx page we redirected to Paytm gateway page and on successfull payment then redirected to PaymentGateway.aspx page .
 
Cart.aspx page------------------->Paytm Gateway Page-------------------------> PaymentGateway.aspx
 
Plz Help..
Thanks

Answers (18)