hi
this is code that I used in website:
private void createTemporaryLink()
{
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();
}
}
but below error happen:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 402: conn.Open();
Line 403: DataTable dtOrder = Session["Order"] as DataTable;
Line 404: foreach (DataRow row in dtOrder.Rows)
Line 405: {
Line 406: foreach (GridViewRow row1 in GridView1.Rows)
|
how I can solve this error?
Best regards
neda