| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1502 人关注过本帖
标题:[求助]未将对象引用设置到对象的实例
取消只看楼主 加入收藏
wjh_36
Rank: 1
等 级:新手上路
帖 子:81
专家分:0
注 册:2006-5-10
收藏
 问题点数:0 回复次数:5 
[求助]未将对象引用设置到对象的实例

Dim conn As New SqlConnection
conn.ConnectionString = ConfigurationSettings.AppSettings("aa")
Dim cmd As New SqlCommand

cmd.CommandText = "select u_id as 编号,u_name as 姓名,u_sex as 性别,u_indate as 入学时间,u_zhy as 所学专业,u_dw as 所在单位 from info where u_id='" & TextBox1.Text & "'"
cmd.Connection = conn
conn.Open()
Dim dr As New SqlDataAdapter
Dim ds As New DataSet
dr.Fill(ds, "info")
DataGrid1.DataSource = ds.Tables("info")
DataGrid1.DataBind()
conn.Close()




出现错误如下:

“/dn”应用程序中的服务器错误。

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

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

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

源错误:

行 42: 
行 43:         cmd.CommandText = "select u_id as 编号,u_name as 姓名,u_sex as 性别,u_indate as 入学时间,u_zhy as 所学专业,u_dw as 所在单位 from info where u_id='" & TextBox1.Text & "'"
行 44:         cmd.Connection = conn
行 45:         conn.Open()
行 46:         Dim dr As New SqlDataAdapter

源文件: c:\inetpub\wwwroot\dn\cbh.aspx.vb 行: 44

堆栈跟踪:

[NullReferenceException: 未将对象引用设置到对象的实例。]
   dn.chaxun.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\dn\cbh.aspx.vb:44
   System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   System.Web.UI.Page.ProcessRequestMain()

请大家帮忙给解决一下,谢谢拉!!!!!!!!!!!11
搜索更多相关主题的帖子: 实例 对象 设置 
2006-05-15 10:30
wjh_36
Rank: 1
等 级:新手上路
帖 子:81
专家分:0
注 册:2006-5-10
收藏
得分:0 

我就是看不出来啊
代码也没什么错误,但运行老是出现那个错误,我都郁闷死了
难道我的电脑罢工拉


2006-05-16 08:53
wjh_36
Rank: 1
等 级:新手上路
帖 子:81
专家分:0
注 册:2006-5-10
收藏
得分:0 

有啊 我在刚开头都写了:imports system.data
imports system.data.sqlclint
这两句话


2006-05-16 10:10
wjh_36
Rank: 1
等 级:新手上路
帖 子:81
专家分:0
注 册:2006-5-10
收藏
得分:0 
谢谢大家
这个问题已经解决了

2006-05-16 15:51
wjh_36
Rank: 1
等 级:新手上路
帖 子:81
专家分:0
注 册:2006-5-10
收藏
得分:0 
别人告诉我的

把一下代码:
cmd.CommandText = "select u_id as 编号,u_name as 姓名,u_sex as 性别,u_indate as 入学时间,u_zhy as 所学专业,u_dw as 所在单位 from info where u_id='" & TextBox1.Text & "'"
cmd.Connection = conn
conn.Open()
Dim dr As New SqlDataAdapter
Dim ds As New DataSet
dr.Fill(ds, "info")
DataGrid1.DataSource = ds.Tables("info")
DataGrid1.DataBind()
conn.Close()
改成了如下代码


Dim dr As New SqlDataAdapter
Dim ds As New DataSet
conn.Open()
cmd.CommandText = "select u_id as 编号,u_name as 姓名,u_sex as 性别,u_indate as 入学时间,u_zhy as 所学专业,u_dw as 所在单位 from info where u_id='" & TextBox1.Text & "'"
cmd.Connection = conn
cmd.CommandType = CommandType.Text
dr.SelectCommand = comm
dr.Fill(ds, "info")
DataGrid1.DataSource = ds.Tables("info")
DataGrid1.DataBind()
conn.Close()

2006-05-17 10:32
wjh_36
Rank: 1
等 级:新手上路
帖 子:81
专家分:0
注 册:2006-5-10
收藏
得分:0 

我也不知道,可能是我sql语句的错误也不知道什么的
我换成那几句后,就没在出错了


2006-05-18 09:11
快速回复:[求助]未将对象引用设置到对象的实例
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016343 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved