主题:关于图片上传的问题
public class test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox CardID;
protected System.Web.UI.WebControls.Button Button1;
protected SqlConnection myConnection=new SqlConnection();
protected HtmlInputFile UP_FILE;
protected System.Web.UI.WebControls.Label txtMessage;
protected Int32 FileLength=0;
protected void Button_Submit(System.Object sender,System.EventArgs e)
{
HttpPostedFile UpFile=UP_FILE.PostedFile;
FileLength=UpFile.ContentLength;
try
{
if(FileLength==0)
{
txtMessage.Text="<b>请选择文件</b>";
}
else
{
Byte[] FileByteArray=new byte[FileLength];
Stream StreamObject =UpFile.InputStream;
StreamObject.Read(FileByteArray,0,FileLength);
string strconn1= ConfigurationSettings.AppSettings["dsn"];
SqlConnection myConnection1= new SqlConnection (strconn1);
string SqlCmd="insert into HYZP (CardID,ImageData,ImageContentType,ImageSize) values (@CardID,@Image,@ContentType,@ImageSize)";
SqlCommand CmdObj= new SqlCommand(SqlCmd,myConnection1);
CmdObj.Parameters.Add("@CardID",SqlDbType.VarChar,50).Value=CardID.Text;
CmdObj.Parameters.Add("@Image",SqlDbType.Binary,FileLength).Value=FileByteArray;
CmdObj.Parameters.Add("@ContentType",SqlDbType.VarChar,50).Value=UpFile.ContentType;
CmdObj.Parameters.Add("@ImageSize",SqlDbType.BigInt,8).Value=UpFile.ContentLength;
myConnection1.Open();
CmdObj.ExecuteNonQuery();
myConnection.Close();
txtMessage.Text="<p><b>OK!你已经成功上传了你的图片</b>";
}
}
catch(Exception ex)
{
txtMessage.Text=ex.Message.ToString();
}
}
请问老提示下面的错误是哪里的错误??/?
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 28: protected void Button_Submit(System.Object sender,System.EventArgs e)
行 29: {
行 30: HttpPostedFile UpFile=UP_FILE.PostedFile;
行 31: FileLength=UpFile.ContentLength;
行 32: try
源文件: c:\inetpub\wwwroot\jszx\test.aspx.cs 行: 30
{
protected System.Web.UI.WebControls.TextBox CardID;
protected System.Web.UI.WebControls.Button Button1;
protected SqlConnection myConnection=new SqlConnection();
protected HtmlInputFile UP_FILE;
protected System.Web.UI.WebControls.Label txtMessage;
protected Int32 FileLength=0;
protected void Button_Submit(System.Object sender,System.EventArgs e)
{
HttpPostedFile UpFile=UP_FILE.PostedFile;
FileLength=UpFile.ContentLength;
try
{
if(FileLength==0)
{
txtMessage.Text="<b>请选择文件</b>";
}
else
{
Byte[] FileByteArray=new byte[FileLength];
Stream StreamObject =UpFile.InputStream;
StreamObject.Read(FileByteArray,0,FileLength);
string strconn1= ConfigurationSettings.AppSettings["dsn"];
SqlConnection myConnection1= new SqlConnection (strconn1);
string SqlCmd="insert into HYZP (CardID,ImageData,ImageContentType,ImageSize) values (@CardID,@Image,@ContentType,@ImageSize)";
SqlCommand CmdObj= new SqlCommand(SqlCmd,myConnection1);
CmdObj.Parameters.Add("@CardID",SqlDbType.VarChar,50).Value=CardID.Text;
CmdObj.Parameters.Add("@Image",SqlDbType.Binary,FileLength).Value=FileByteArray;
CmdObj.Parameters.Add("@ContentType",SqlDbType.VarChar,50).Value=UpFile.ContentType;
CmdObj.Parameters.Add("@ImageSize",SqlDbType.BigInt,8).Value=UpFile.ContentLength;
myConnection1.Open();
CmdObj.ExecuteNonQuery();
myConnection.Close();
txtMessage.Text="<p><b>OK!你已经成功上传了你的图片</b>";
}
}
catch(Exception ex)
{
txtMessage.Text=ex.Message.ToString();
}
}
请问老提示下面的错误是哪里的错误??/?
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 28: protected void Button_Submit(System.Object sender,System.EventArgs e)
行 29: {
行 30: HttpPostedFile UpFile=UP_FILE.PostedFile;
行 31: FileLength=UpFile.ContentLength;
行 32: try
源文件: c:\inetpub\wwwroot\jszx\test.aspx.cs 行: 30