Server Error in '/' Application.
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 34: }
Line 35:
Line 36: string strcon = ConfigurationManager.AppSettings["payrollConnectionString"].ToString();
Line 37: protected void Page_Load(object sender, EventArgs e)
Line 38: {
Source File: C:\Users\Surya\Documents\Visual Studio 2008\Projects\Surya\imageexport\imageexport\Default.aspx.cs Line: 36
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
imageexport._Default..ctor() in C:\Users\Surya\Documents\Visual Studio 2008\Projects\Surya\imageexport\imageexport\Default.aspx.cs:36
ASP.default_aspx..ctor() in c:\Users\Surya\AppData\Local\Temp\Temporary ASP.NET Files\root\d163ef2f\853db724\App_Web_s6dguo8s.0.cs:0
__ASP.FastObjectFactory_app_web_s6dguo8s.Create_ASP_default_aspx() in c:\Users\Surya\AppData\Local\Temp\Temporary ASP.NET Files\root\d163ef2f\853db724\App_Web_s6dguo8s.2.cs:0
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +119
System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +33
System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +40
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +160
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +93
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
I got this error.
Can anyone help me?
My .cs code is:
namespace imageexport
{
public partial class _Default : System.Web.UI.Page
{
class Problem
{
static void Main()
{
Problem problem = null;
}
public int ProblemProperty
{
get { return 0; }
}
public string ProblemMethod()
{
return null;
}
}
string strcon = ConfigurationManager.AppSettings["payrollConnectionString"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridData();
}
}
protected void btnUpload_Click(object sender, EventArgs e)
{
if (fileuploadImage.HasFile)
{
int length = fileuploadImage.PostedFile.ContentLength;
byte[] imgbyte = new byte[length];
HttpPostedFile img = fileuploadImage.PostedFile;
img.InputStream.Read(imgbyte, 0, length);
string imagename = txtImageName.Text;
SqlConnection connection = new SqlConnection(strcon);
connection.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO Image (ImageName,Image) VALUES (@imagename,@imagedata)", connection);
cmd.Parameters.Add("@imagename", SqlDbType.VarChar, 50).Value = imagename;
cmd.Parameters.Add("@imagedata", SqlDbType.Image).Value = imgbyte;
int count = cmd.ExecuteNonQuery();
connection.Close();
if (count == 1)
{
BindGridData();
txtImageName.Text = string.Empty;
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('" + imagename + " image inserted successfully')", true);
}
}
}
private void BindGridData()
{
SqlConnection connection = new SqlConnection(strcon);
SqlCommand command = new SqlCommand("SELECT imagename,ImageID from [Image]", connection);
SqlDataAdapter daimages = new SqlDataAdapter(command);
DataTable dt = new DataTable();
daimages.Fill(dt);
gvImages.DataSource = dt;
gvImages.DataBind();
gvImages.Attributes.Add("bordercolor", "black");
}
}
}
My handler .ashx Code is:
namespace imageexport
{
public partial class _Default : System.Web.UI.Page
{
class Problem
{
static void Main()
{
Problem problem = null;
}
public int ProblemProperty
{
get { return 0; }
}
public string ProblemMethod()
{
return null;
}
}
string strcon = ConfigurationManager.AppSettings["payrollConnectionString"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridData();
}
}
protected void btnUpload_Click(object sender, EventArgs e)
{
if (fileuploadImage.HasFile)
{
int length = fileuploadImage.PostedFile.ContentLength;
byte[] imgbyte = new byte[length];
HttpPostedFile img = fileuploadImage.PostedFile;
img.InputStream.Read(imgbyte, 0, length);
string imagename = txtImageName.Text;
SqlConnection connection = new SqlConnection(strcon);
connection.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO Image (ImageName,Image) VALUES (@imagename,@imagedata)", connection);
cmd.Parameters.Add("@imagename", SqlDbType.VarChar, 50).Value = imagename;
cmd.Parameters.Add("@imagedata", SqlDbType.Image).Value = imgbyte;
int count = cmd.ExecuteNonQuery();
connection.Close();
if (count == 1)
{
BindGridData();
txtImageName.Text = string.Empty;
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('" + imagename + " image inserted successfully')", true);
}
}
}
private void BindGridData()
{
SqlConnection connection = new SqlConnection(strcon);
SqlCommand command = new SqlCommand("SELECT imagename,ImageID from [Image]", connection);
SqlDataAdapter daimages = new SqlDataAdapter(command);
DataTable dt = new DataTable();
daimages.Fill(dt);
gvImages.DataSource = dt;
gvImages.DataBind();
gvImages.Attributes.Add("bordercolor", "black");
}
}
}
Can anyone help me?
How to clear this error?