关于网友提出的“未授予用户在此计算机上的请求登录类型 用户代码未处理NullReferenceException: 未将对象引用设置到对象的实例”问题疑问,本网通过在网上对“未授予用户在此计算机上的请求登录类型 用户代码未处理NullReferenceException: 未将对象引用设置到对象的实例”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题:未授予用户在此计算机上的请求登录类型 用户代码未处理NullReferenceException: 未将对象引用设置到对象的实例
描述: 我做一个设备保养管理系统,用按钮事件来查询在两个事件段需要保养的设备,我数据库中定义的时间为datetime,通过点击button来查询,不过在查询中老是显示“用户代码未处理NullReferenceException: 未将对象引用设置到对象的实例。排除提示:使用new关键字创建对象实例,在调用方法前检查确定对象是否为空”
cmd.Parameters("@xh").Value = CDate(StartListBox.SelectedItem.Text) 显示这句诗上面的问题,请高手指教,急啊,在线等。
Protected Sub ShowBYSQButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ShowBYSQButton.Click
Dim con As New SqlConnection()
con.ConnectionString = "Data Source=UPC-DING;Initial Catalog=bysj;User ID=sa ;"
con.Open()
Dim sql As String
sql = "SELECT * FROM [保养申请] where 申请日期 between '@xh' and '@xb'"
Dim ds As New DataSet()
Dim adp As New SqlDataAdapter()
Dim cmd As New SqlCommand
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.Parameters.Clear()
cmd.CommandText = sql
cmd.Parameters.Add("@xh", SqlDbType.DateTime)
cmd.Parameters.Add("@xb", SqlDbType.DateTime)
cmd.Parameters("@xh").Value = CDate(StartListBox.SelectedItem.Text)
cmd.Parameters("@xb").Value = CDate(EndListBox.SelectedItem.Text)
adp.SelectCommand = cmd
adp.Fill(ds, "by")
GridView1.DataSource = ds.Tables("by").DefaultView
GridView1.DataBind()
con.Close()
End Sub
错误具体信息:
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 33: ' cmd.Parameters("@xh").Value = CDate(StartListBox.SelectedItem.Text)
行 34: ' cmd.Parameters("@xb").Value = CDate(EndListBox.SelectedItem.Text)
行 35: cmd.Parameters("@xh").Value = StartListBox.SelectedItem.Text
行 36: cmd.Parameters("@xb").Value = EndListBox.SelectedItem.Text
行 37:
源文件: E:\毕业设计作业\保养设备管理\保养申请单.aspx.vb 行: 35
堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
保养设备管理_保养申请单.ShowBYSQButton_Click(Object sender, EventArgs e) in E:\毕业设计作业\保养设备管理\保养申请单.aspx.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +117
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3838
以上介绍了“未授予用户在此计算机上的请求登录类型 用户代码未处理NullReferenceException: 未将对象引用设置到对象的实例”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3416615.html