未将对象引用设置到对象的实例 的错误如何解决?
datagrid 超级链接出现的错误
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误: 第42行出错了,可我不知道错在什么地方(已经转到连接页了)
行 39: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
行 40: Dim str As String
行 41: str = Request( "fuck ").ToString()
行 42: Dim conn As OleDbConnection = New OleDbConnection( "Provider=Microsoft.Jet.OleDb.4.0;Data Source= " & Server.MapPath( "logon.mdb "))
行 43: Dim cmd As OleDbCommand = New OleDbCommand( "select * from chuzu where fuck= ' " & str & " ' ", conn)
以下是代码
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim str As String
str = Request( "fuck ").ToString()
Dim conn As OleDbConnection = New OleDbConnection( "Provider=Microsoft.Jet.OleDb.4.0;Data Source= " & Server.MapPath( "logon.mdb "))
Dim cmd As OleDbCommand = New OleDbCommand( "select * from chuzu where fuck= ' " & str & " ' ", conn)
Dim odr As OleDbDataReader
Try
conn.Open()
odr = cmd.ExecuteReader()
If odr.Read() Then
Label1.Text = odr.Item(0)
Label2.Text = odr.Item(1)
Label3.Text = odr.Item(2)
Label4.Text = odr.Item(3)
Label5.Text = odr.Item(4)
Label6.Text = odr.Item(5)