Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Database > OLEDB

OLEDB Topics related to OLEDB with VB.NET

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-13-2007, 9:00 AM
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0
 
Join Date: Jun 2007
Posts: 70
Reputation: 37
ninjaimp is on a distinguished programming path ahead
Exclamation System.NullReferenceException error!

Hi

I am very new to vb.net and still trying to get my head around it. I am trying to connect to an access db and then update a table with some test info

my code is:

Code:
Dim con As New OleDb.OleDbConnection
        Dim sql As String
        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        Dim MakeTableSQL As String
        Dim MySql As String
        Dim MySql2 As String
        Dim MySql3 As String

        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\email.mdb"

        sql = "SELECT * FROM Email"
        da = New OleDb.OleDbDataAdapter(sql, con)

        Dim cb As New OleDb.OleDbCommandBuilder(da)
        Dim dsNewRow As DataRow

        dsNewRow = ds.Tables("Labels").NewRow()

        dsNewRow.Item("Body") = "Test"

        ds.Tables("Labels").Rows.Add(dsNewRow)

        da.Update(ds, "Labels")

        MsgBox("New Record added to the Database")
eveytime i run the code i get the error 'System.NullReferenceException'

i wondered if anyone could help?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-20-2007, 11:53 AM
cjard's Avatar
VB.NET Forum All-Mighty
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Apr 2006
Age: 65
Posts: 6,442
Reputation: 807
cjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond repute
Default

See my signature.. DW2 link. Section "Creating a Simple Data App".
Also read the DNU link
__________________
DW1 DW2 DW3 DW4 DNU PQ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-27-2008, 11:36 PM
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Jan 2008
Posts: 30
Reputation: 29
kyoshiro is on a distinguished programming path ahead
Default

your problem seems simple, i guess you have only forgotten to create an instance of DataRow : drow = new datarow

unable to create an instance of an object will issue a nullreference exception

hope this would be helpful
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-28-2008, 2:07 AM
VB.NET Forum Enthusiast
.NET Framework: .NET 1.1 (VS 2003)
 
Join Date: Jan 2008
Posts: 63
Reputation: 46
Rocksteady will become famous soon enough
Default

Quote:
Originally Posted by kyoshiro View Post
your problem seems simple, i guess you have only forgotten to create an instance of DataRow : drow = new datarow

unable to create an instance of an object will issue a nullreference exception

hope this would be helpful
It's not that at all.

You're trying to access a table that doesn't exist.

The dataset contains no tables.

Tables("Label") will give you a nullreference exception.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 6:17 AM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.