当运行时会有一个这样的错误:未将对象引用设置到对象的实例;
问题代码是:HttpPostedFile UpFile = UP_FILE.PostedFile; //HttpPostedFile对象,用于读取图象文件属性
FileLength = UpFile.ContentLength;红色的那句,不理解什么意思啊,请各位大哥、大姐帮助!
问题代码是:HttpPostedFile UpFile = UP_FILE.PostedFile; //HttpPostedFile对象,用于读取图象文件属性
FileLength = UpFile.ContentLength;红色的那句,不理解什么意思啊,请各位大哥、大姐帮助!
解决方案 »
- c# 截取 联通下载 后面的 超链接 href=""
- C#能查看本机往外发送数据包吗?折磨好几天了。另加50分
- 本人初学C#谁来帮下谢谢!
- System.ComponentModel.Design.ServiceContainer这个类有人用过么?关于插件的。
- 经常听到大家谈.net底层,请问这是指什么!想了解一些,怎么学呀
- c1flex 控件很好用,有个问题不知道怎么解决?
- 一个用c#网络编程
- c#游戏开发
- C#+VS2010+WINMM.DLL自制48键电子琴 吐血免分大放送!!
- 数据库问题 通宵等待 搞不定真的不能睡觉啊
- c# winform中DateTimePicker 如何赋值?
- 使用oledb连接dbf文件时出现“外部表不是预期表格式”错误
HttpPostedFile upfile =aa.PostedFile; //HttpPostedFile对象,用于读取图象文件属性
FileLength = upfile.ContentLength;
怎么会接收不到图片的属性呢?郁闷,请高手们不吝赐教啊!
HttpPostedFile UpFile = UP_FILE.PostedFile; //HttpPostedFile对象,用于读取图象文件属性
FileLength = UpFile.ContentLength;//记录文件长度
if (FileLength > 0)
{
//建立SQL Server链接
SqlConnection Con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
String SqlCmd = "";
SqlCommand CmdObj = new SqlCommand(SqlCmd, Con);
//记录文件长度,读取时使用
SqlTransaction trans;
Con.Open();
trans = Con.BeginTransaction();
CmdObj.Transaction = trans;
try
{
Byte[] FileByteArray = new Byte[FileLength]; //图象文件临时储存Byte数组
Stream StreamObject = UpFile.InputStream;//建立数据流对像
//读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
StreamObject.Read(FileByteArray, 0, FileLength); ;
CmdObj.CommandText = "update a set Image=@Image,ContentType=@ContentType,ImageSize=@ImageSize where id=1";
CmdObj.Parameters.Add("@Image", SqlDbType.Binary, FileLength).Value = FileByteArray;
CmdObj.Parameters.Add("@ContentType", SqlDbType.VarChar, 50).Value = UpFile.ContentType;//记录文件类型
//把其它单表数据记录上传
//CmdObj.Parameters.Add("@ImageDescription", SqlDbType.VarChar, 200).Value = txtDescription.Text;
//记录文件长度,读取时使用
CmdObj.Parameters.Add("@ImageSize", SqlDbType.BigInt, 8).Value = UpFile.ContentLength;
CmdObj.ExecuteNonQuery();
trans.Commit();
Con.Close();
}
catch (Exception ex)
{
Page.RegisterStartupScript("Alert", "<script language=javascript>alert('" + ex.Message + "');</script>");
trans.Rollback();
Con.Close();
}
}
对象未实例化,只能说明UP_FILE.PostedFile有问题