周末交作业了,50分求助:“
未将对象引用设置到对象的实例”
参考了别人的一个例子,向Sql数据库中插入图片时,出现:“未将对象引用设置到对象的实例”,错误在fileLength = Up_file.PostedFile.ContentLength;这句,调试时还出现在 System.NullReferenceException 中第一次偶然出现的“App_Web_5y6xpzfn.dll”类型的异常的说明,以下是原代码:
using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.IO;
using System.Drawing;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class UploadImage : System.Web.UI.Page
{
protected HtmlInputFile Up_file;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int fileLength ;
Up_file = new HtmlInputFile();
fileLength = Up_file.PostedFile.ContentLength;
try
{
if (fileLength == 0)
{
LB_message.Text = " <b> 请你选择你要上传的文件 </b> ";
}
else
{
Byte[] FileByteArray = new Byte[fileLength];
Stream StreamObject = Up_file.PostedFile.InputStream;
StreamObject.Read(FileByteArray, 0, fileLength);
SqlConnection Con = new SqlConnection( "Data Source=(local);Initial Catalog=xiaoyuan;uid=sa;pwd=sa; ");
string SqlCmd