读书人

大家来帮小弟我看看这段程序

发布时间: 2012-03-14 12:01:13 作者: rapoo

大家来帮我看看这段程序,
,,,,


private void UploadBtn_Click(object sender, System.EventArgs e)
{

string FileNames=MyFile.PostedFile.FileName;
int fileLength = MyFile.PostedFile.ContentLength;
byte[] fileData = new byte[fileLength];

string fileType = MyFile.PostedFile.ContentType;

OleDbConnection con =DB.CreateCon ();
con.Open();
string str= "insert into link (logo) values (?) ";
OleDbCommand cmd=new OleDbCommand(str,con);

OleDbParameter p1=new OleDbParameter( " ",OleDbType.VarChar ,200);
p1.Value=FileNames;
cmd.Parameters.Add(p1);

cmd.ExecuteNonQuery();
con.Close();
}


一单击上传按钮时出现以下错误> > > > > > > > > > > > > > > > >

未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:


行 88: {
行 89:
行 90: string FileNames=MyFile.PostedFile.FileName;
行 91: int fileLength = MyFile.PostedFile.ContentLength;
行 92: byte[] fileData = new byte[fileLength];


源文件: c:\inetpub\wwwroot\dengshi\manageweb\firendlink.aspx.cs 行: 90


[解决办法]
System.Web.HttpPostedFile ff=控件名.postFiled;
加在 string FileNames=MyFile.PostedFile.FileName;
上面
[解决办法]
MyFile 是 file控件么


[解决办法]
MyFile不是你自己定义的控件的ID吗??

读书人网 >asp.net

热点推荐