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()