0
Reply

Object reference not set to an instance of an object in asp.

Reylin Markose

Reylin Markose

May 17 2018 6:08 AM
133
this is my code...
-------------------- 
if (!fupImage.HasFile)
{
// File was sent
string stdid = Session["StdId"].ToString();
int length = fupImage.PostedFile.ContentLength;
if (length > 500 * 1024)
{
Response.Write("Ur image is too large");
}
else
{
byte[] pic = new byte[length];
//HttpPostedFile img = fupImage.PostedFile; img.InputStream.Read(pic, 0, length);
fupImage.PostedFile.InputStream.Read(pic, 0, length);
string res = std.StudentImageUpload(stdid, pic);
Response.Redirect("Dashboard.aspx");
}
}
else
{
// No file
}
this is my class function
-----------------------------
public string StudentImageUpload(string stdid,byte[] pic)
{
try
{
GetConnect();
SqlCommand cmd = new SqlCommand("insert into Std_Photo(StdId,Phto) values(@stdid,@photo)", SqlCon);
cmd.Parameters.AddWithValue("@stdid",stdid);
cmd.Parameters.Add("@photo", SqlDbType.Binary).Value=pic;
string res = cmd.ExecuteNonQuery().ToString();
GetClosed();
return res;
}
catch (Exception ex)
{
throw ex;
}
}
--------------------------------
my problem is  , executing time this line  int length = fupImage.PostedFile.ContentLength;  
got error for  Object reference not set to an instance of an object in asp.... how to solve this problem.?
 Thanks in advnce.