Hai I am having a file[stored in the form of varbinary(MAX) ]
Concept:Click Download button to save the Corresponding Word file from the SQL Database 2005
while downloading that file through gridview i got an error
"Object reference not set to an instance of an object." pointing to
GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow; Code: LinkButton lnkbtn = sender as LinkButton;
GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
int fileid = Convert.ToInt32(dwnstGridView.DataKeys[gvrow.RowIndex].Value.ToString());
SqlCommand objgv = new SqlCommand("select dt_docfile from userDownload where dt_userid=@dt_userid", objsqlcon);
objgv.Parameters.AddWithValue("@dt_userid", fileid);
SqlDataReader dr = objgv.ExecuteReader();
if (dr.Read())
{
Response.ContentType = dr["FileType"].ToString();
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + dr["FileName"] + "\"");
Response.BinaryWrite((byte[])dr["FileData"]);
Response.End();
}
}
why this error arises ?
Tell any other code
Help me as short as possible
Regards