nedash says:
DataTable dtOrder = Session[
"Order"
]
as
DataTable;
1) You need to check is Session["Order"] is not null might be it causing error because of session is null as you are assigning Session["Order"] value to DataTable so it’s an empty DataTable with no any records.
2) You need to be sure that session value for Session["Order"] is assigned then only you can perform the action which you are coded.
3) So check from where your Session["Order"] value get sets and on createTemporaryLink() method you need to handle the session null checking by using below code if your session is not null then only it will perform next operation.
C#
private void createTemporaryLink()
{
/* Perform Action When only Session["Order"] is not null*/
if (Session["Order"] != null)
{
using (SqlConnection conn = General.GetConnection())
{
conn.Open();
DataTable dtOrder = Session["Order"] as DataTable;
foreach (DataRow row in dtOrder.Rows)
{
foreach (GridViewRow row1 in GridView1.Rows)
{
using (SqlCommand _cmd = General.GetCommand("Downloadurl_insert", conn))
{
string ipAddress;
ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipAddress == "" || ipAddress == null)
ipAddress = Request.ServerVariables["REMOTE_ADDR"];
string name = (row1.FindControl("LblName") as Label).Text;
_cmd.Parameters.AddWithValue("@downloadTitle", name);
_cmd.Parameters.AddWithValue("@url", "~/downloads/" + name + ".mkv");
_cmd.Parameters.AddWithValue("@DownloadToken", GetDownloadToken(10));
_cmd.Parameters.AddWithValue("@IpAddress", ipAddress);
_cmd.Parameters.AddWithValue("@Hits", "0");
_cmd.Parameters.AddWithValue("@Downloaded", "false");
_cmd.Parameters.AddWithValue("@mobile", LblMob.Text);
_cmd.Parameters.AddWithValue("@Authority", Request.QueryString["Authority"].ToString());
_cmd.Parameters.AddWithValue("@Pcode", row["Code"]);
_cmd.Parameters.AddWithValue("@Ptype", row["Type"]);
_cmd.Parameters.AddWithValue("@PSectionName", row["SectionName"]);
_cmd.Parameters.AddWithValue("@PName", row["Name"]);
_cmd.Parameters.AddWithValue("@OrderType", row["buy"]);
_cmd.Parameters.AddWithValue("@format", row["Quality"]);
_cmd.Parameters.AddWithValue("@Quantity", row["Quanyity"]);
_cmd.Parameters.AddWithValue("@PriceT", row["PriceT"]);
conn.Open();
_cmd.ExecuteNonQuery();
conn.Close();
}
}
}
ShowTemporaryLink();
}
}
}