求助: 未将对象引用设置到对象的实例。

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

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

源错误:


行 21: if (FileName.Text.Trim()!="")
行 22: {
行 23: PictureDB picture = new PictureDB();
行 24: Stream pictureStream = upfile.PostedFile.InputStream;
行 25: byte[] pictureData = new byte[upfile.PostedFile.ContentLength];


源文件: d:\编程\处理数据库中的图片\Default.aspx.cs 行: 23


我有实例化啊!!!!!怎么回事啊??
...全文
265 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenyf_72 2010-10-15
  • 打赏
  • 举报
回复
嗯,好像是这的问题!!
孟子E章 2010-10-15
  • 打赏
  • 举报
回复
ConfigurationSettings.AppSettings["ConnectionString"]返回的是null
检查web.config里面的配置
chenyf_72 2010-10-15
  • 打赏
  • 举报
回复
public class PictureDB
{
public PictureDB(){}
private readonly string ConnectionString = ConfigurationSettings.AppSettings["ConnectionString"].ToString();
public int AddPicture(String sPictureDesn, byte[] bPictureData, String sPictureType)
{
SqlConnection conn = new SqlConnection(ConnectionString);

SqlCommand myCommand = new SqlCommand("Pr_AddPicture", conn);
myCommand.CommandType = CommandType.StoredProcedure;

SqlParameter parameterPictureDesn = new SqlParameter("@PictureDesn", SqlDbType.VarChar, 50);
parameterPictureDesn.Value = sPictureDesn;
myCommand.Parameters.Add(parameterPictureDesn);

SqlParameter parameterPictureData = new SqlParameter("@PictureData", SqlDbType.Image);
parameterPictureData.Value = bPictureData;
myCommand.Parameters.Add(parameterPictureData);

SqlParameter parameterPictureType = new SqlParameter("@PictureType", SqlDbType.VarChar, 50);
parameterPictureType.Value = sPictureType;
myCommand.Parameters.Add(parameterPictureType);

SqlParameter parameterPictureID= new SqlParameter("@PictureID", SqlDbType.Int,4);
parameterPictureID.Direction = ParameterDirection.ReturnValue;
myCommand.Parameters.Add(parameterPictureID);

try
{
conn.Open();
}
catch (System.Exception ex)
{
throw new Exception(ex.Message, ex);
}
try
{
myCommand.ExecuteNonQuery();
}
catch (System.Exception ex)
{
throw new Exception(ex.Message, ex);
}
finally{
if (conn.State==ConnectionState.Open){
conn.Close();
}
}
return (int)parameterPictureID.Value;
}

public SqlDataReader GetSinglePicture(int nPictureID)
{
SqlConnection conn = new SqlConnection(ConnectionString);
SqlCommand myCommand = new SqlCommand("Pr_GetSinglePicture", conn);
myCommand.CommandType = CommandType.StoredProcedure;

SqlParameter parameterPictureID = new SqlParameter("@PictureID", SqlDbType.Int, 4);
parameterPictureID.Value = nPictureID;
myCommand.Parameters.Add(parameterPictureID);
SqlDataReader dr = null;
try
{
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (System.Exception ex)
{
throw new Exception(ex.Message, ex);
}
return dr;
}

}
孟子E章 2010-10-15
  • 打赏
  • 举报
回复
贴PictureDB类的代码,是PictureDB里面错误
chenyf_72 2010-10-15
  • 打赏
  • 举报
回复
顶下,高手来解答啊!
chenyf_72 2010-10-15
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 beyond_me21 的回复:]
这个PictureDB类有和引用的页相同的命名空间吗?
[/Quote]

都没用命名空间啊。
beyond_me21 2010-10-15
  • 打赏
  • 举报
回复
这个PictureDB类有和引用的页相同的命名空间吗?
chenyf_72 2010-10-15
  • 打赏
  • 举报
回复
在这个cs文件里写的类,cs文件在 App_Code文件夹里面。
chenyf_72 2010-10-15
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wuyq11 的回复:]
PictureDB怎么定义的,是DLL类库中的类吗?
[/Quote]

不是,就是随便添加的一个 cs文件。。
wuyq11 2010-10-15
  • 打赏
  • 举报
回复
PictureDB怎么定义的,是DLL类库中的类吗?
chenyf_72 2010-10-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wuyq11 的回复:]
PictureDB什么
添加相关引用
[/Quote]

麻烦楼上说清楚一些!!
wuyq11 2010-10-15
  • 打赏
  • 举报
回复
PictureDB什么
添加相关引用

62,272

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧