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:

The source code that generated this unhandled exception can only be
shown when compiled in debug mode. To enable this, please follow one
of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated
the error. Example:

  <%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your
application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given
application to be compiled in debug mode. The first technique will
cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/
performance overhead. You should make sure that an application has
debugging disabled before deploying into production scenario.

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
   _Default.UpLoadImageFile(FileInfo imageInfo) +771
   _Default.Button1_Click(Object sender, EventArgs e) +405
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +110
 
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+36
   System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1565


see c# code i tried in sql server its working fine

On Jun 24, 3:44 pm, Processor Devil <[email protected]> wrote:
> Object reference not set to an instance of an object
> this is not all it shows you. Can you please specify closer the expection?
>
> 2009/6/24 nag <[email protected]>
>
>
>
>
>
> > hii dear all,
> > im getting following error while uploading file to mysql database
>
> > Object reference not set to an instance of an object
>
> > here is my code please anyone help me to do the same
>
> >  <table align ="center" class="panel1" style="width: 99%; height:
> > 118px;">
> >            <tr>
> >                <td style="width: 464px; height: 21px; text-align:
> > left;">
> >                    Description: &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;
> > &nbsp; &nbsp;<asp:TextBox ID="txtFileName" runat="server"></
> > asp:TextBox></td>
> >            </tr>
> >            <tr>
>
> >            </tr>
> >            <tr>
> >                <td style="width: 464px; text-align: left;">
> >                    Document: &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;
> > &nbsp; &nbsp;<input id="File1" runat="server" type="file"
> > style="width: 266px" /></td>
> >            </tr>
> >            <tr>
> >                <td style="width: 464px; height: 26px;">
> >                    <asp:Button ID="Button1" runat="server"
> > Text="Upload" OnClick="Button1_Click" /></td>
> >            </tr>
>
> >        </table>
>
> > C# code
>
> > String strConnectionString = "Driver={MySQL ODBC 3.51
> > Driver};Server=mysql8.brinkster.com;Database=dv;user
> > id=dv;password=bv";
>
> >    protected void Button1_Click(object sender, EventArgs e)
> >    {
> >        FileInfo imageInfo = new FileInfo(File1.Value.Trim());
> >        //if (!imageInfo.Exists)
> >        //    this.RegisterClientScriptBlock("alertLabel1",
> > "<script>alert('please select one image file.');</script>");
> >        //else
> >        //{
> >            switch (imageInfo.Extension.ToUpper())
> >            {
> >                case ".JPG": this.UpLoadImageFile(imageInfo); break;
> >                case ".GIF": this.UpLoadImageFile(imageInfo); break;
> >                case ".BMP": this.UpLoadImageFile(imageInfo); break;
> >                case ".ZIP": this.UpLoadImageFile(imageInfo); break;
> >                case ".DOC": this.UpLoadImageFile(imageInfo); break;
> >                case ".PDF": this.UpLoadImageFile(imageInfo); break;
> >                case ".wmv": this.UpLoadImageFile(imageInfo); break;
> >                default: this.RegisterClientScriptBlock("alertLabel1",
> > "<script>alert('file type error.');</script>"); break;
> >            }
> >        //}
> >    }
> >    private void UpLoadImageFile(FileInfo info)
> >    {
> >        OdbcConnection objConn = null;
> >        OdbcCommand objCom = null;
> >        try
> >        {
> >            byte[] content = new byte[info.Length];
> >            FileStream imagestream = info.OpenRead();
> >            imagestream.Read(content, 0, content.Length);
> >            imagestream.Close();
> >            objConn = new OdbcConnection(strConnectionString);
> >            objCom = new OdbcCommand("insert into dg_admainfile
> > (Description,Filename,Picture,Type,cid,pid)values(?,?,?,?,?,?)",
> > objConn);
> >            OdbcParameter categorynameParameter = new OdbcParameter
> > ("@Description", OdbcType.NVarChar);
> >            if (this.txtFileName.Text.Trim().Equals(""))
> >                categorynameParameter.Value = "Default";
> >            else
> >                objCom.Parameters.Add("@Filename",
> > OdbcType.NVarChar).Value = System.IO.Path.GetFileName
> > (File1.PostedFile.FileName);
> >            objCom.Parameters.Add("@Type", OdbcType.NVarChar).Value =
> > System.IO.Path.GetFileName(File1.PostedFile.ContentType);
> >            objCom.Parameters.Add("@cid", OdbcType.Int).Value = Session
> > ["clientid"].ToString();
> >            objCom.Parameters.Add("@pid", OdbcType.Int).Value = Session
> > ["projectid"].ToString();
> >            categorynameParameter.Value = this.txtFileName.Text.Trim
> > ();
> >            objCom.Parameters.Add(categorynameParameter);
>
> >            OdbcParameter pictureParameter = new OdbcParameter
> > ("@Picture", OdbcType.Image);
> >            pictureParameter.Value = content;
> >            objCom.Parameters.Add(pictureParameter);
> >            objConn.Open();
> >            objCom.ExecuteNonQuery();
> >            objConn.Close();
> >        }
> >        catch (Exception ex)
> >        {
> >            throw new Exception(ex.Message);
> >        }
> >        finally
> >        {
> >            objConn.Close();
> >        }
> >    }
>
> > table name : dg_clientfile
>
> > Description --VARCHAR(45)
>
> > Filename--VARCHAR(45)
> > Picture --LONGBLOB
> > Type ---VARCHAR(45)
>
> > cid --INTEGER
>
> > pid --INTEGER- Hide quoted text -
>
> - Show quoted text -

Reply via email to