|
-
May 9th, 2012, 06:04 PM
#1
Thread Starter
Hyperactive Member
error filling dataset during load event
I am new to asp.net and I'm trying to build my first web page, but when I try to fill a dataset at the page load event I get an error:
object reference not set to instance of object.
Am I missing something? I've done this many times in vb.net. I can't figure out how to step through my code like I do when I'm creating a desktop app, so I don't know exactly where it's failing. I like to be able to see the values of things as it goes through the code.
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label2.Visible = False
Dim dsCheckExisting As New System.Data.DataSet()
dsCheckExisting.Clear()
Dim adLookup As New OleDb.OleDbDataAdapter
adLookup.SelectCommand = New OleDb.OleDbCommand
Dim cnxAd As New OleDb.OleDbConnection
cnxAd.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Chr(34) & "C:\xxx\db1.mdb" & Chr(34) & ""
Dim joe As String = "OCYNFC005679699.994/21/20125/5/2012"
With adLookup.SelectCommand
.Connection = cnxAd
.CommandText = "select * from sheet1 where [unique]=" & joe & ""
.CommandType = CommandType.Text
End With
Try
cnxAd.Open()
adLookup.Fill(dsCheckExisting, "sheet1")
cnxAd.Close()
Catch ex As Exception
cnxAd.Close()
End Try
Dim dr As DataRow
If dsCheckExisting.Tables("sheet1").Rows.Count > 0 Then
For Each dr In dsCheckExisting.Tables("sheet1").Rows
Label1.Text = dr("booked")
Next
End If
End Sub
-
May 9th, 2012, 08:04 PM
#2
Re: error filling dataset during load event
First of all put your code inside "If Not Page.IsPostBack Then". You must also know that your dataset will regenerate after every postback thus you will loose all your data(and must store it if you want to keep it). This is a big difference when programming in asp.net because the web is stateless.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
May 10th, 2012, 01:26 AM
#3
Thread Starter
Hyperactive Member
Re: error filling dataset during load event
Ok. I finally got the correct error and it says:
ex = {"The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine."}
I have microsoft access loaded and activated on this machine, so I don't understand the error message.
Any clues? Also, I've used this code many times before on this machine and only now has it given me this error.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|