AOA Forums AOA Forums AOA Forums Folding For Team 45 AOA Files Home Front Page Become an AOA Subscriber! UserCP Calendar Memberlist FAQ Search Forum Home


Go Back   AOA Forums > Software > Programming and Assembly Language

Programming and Assembly Language Please read this Topic's rules!!


Reply
 
LinkBack Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.
  #1 (permalink)  
Old 12th March, 2011, 08:39 PM
Kaitain's Avatar
Member
Mars Rover Champion, Joust Champion
 
Join Date: September 2001
Location: MK10, UK.
Posts: 4,372
Send a message via MSN to Kaitain Send a message via Skype™ to Kaitain

VB and embedded SQL gah! annoying!

From time to time I have to do some "real" programming (well, more real than IEC 61131 anyway). It's not really my forté.

All I want to do in the example below is connect to an MS Embedded SQL database file, select everything from it (about 12 rows) and display the number of rows in a message box. It halts with a null reference error at line 23.

I'm using this msdn site as a reference. I've cut it down for now just to demonstrate it has a connection - the db has a few dummy rows of data just to prove a point. I can't see what I've got wrong, which no doubt means it's blindingly obvious.

I have previously managed to use just a CreateCommand() and an ExecuteNonQuery() to insert the data into the db file, so I know that my connection string works, the file's OK and the path is valid; however the sqlcedataadapter looks like the right way to do what I need to do.

Help?

Code:
Public Class Form1
    ' the filespec, connection and so forth will be used by multiple forms.
    Public FileSpec As String
    Public dbConnString As String
    Public dbConn As New SqlServerCe.SqlCeConnection("data source = Databases\testdb.sdf")



    Public Sub main()

        Dim dbSqlQuery1 As String

        Dim dbRecords As SqlServerCe.SqlCeDataAdapter = Nothing

        Try
            dbConn.Open()


            ' Select Statement
            Dim dbCommand1 As New SqlServerCe.SqlCeCommand
            dbSqlQuery1 = "select * from accomponent"
            dbCommand1 = dbConn.CreateCommand()
            dbCommand1.CommandText = dbSqlQuery1 ' fails at this point with a null reference error
            dbRecords.SelectCommand = dbCommand1 ' and suggests I define dbCommand1 as "new", which I have


            ' Populate a dataset
            Dim dbDataSet As New DataSet()
            dbRecords.Fill(dbDataSet)

            ' Prove that data exist in the table (should show 12 rows)

            MessageBox.Show("Number of Rows: " & dbDataSet.Tables(0).Rows.Count)

        Finally
            dbConn.Close()
        End Try






    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Otherwise not much happens...
        main()
    End Sub
End Class
__________________
It is by coffee alone I set my mind in motion...

Last edited by Kaitain; 12th March, 2011 at 08:39 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 13th March, 2011, 01:06 AM
Gizmo's Avatar
Chief BBS Administrator
BassTeroids Champion, Global Player Champion, Aim & Fire Champion, Puzzle Maniax Champion, Othello Champion, Canyon Glider Champion, Unicycle Challenge Champion, YetiSports 9: Final Spit Champion, Zed Champion
 
Join Date: May 2003
Location: Webb City, Mo
Posts: 16,178
Send a message via ICQ to Gizmo Send a message via AIM to Gizmo Send a message via MSN to Gizmo Send a message via Yahoo to Gizmo Send a message via Skype™ to Gizmo

Are you certain your datasource path is correct? I really can't see a reason it shouldn't work, although I'm not an expert with the WinCE stuff.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 13th March, 2011, 10:27 AM
Kaitain's Avatar
Member
Mars Rover Champion, Joust Champion
 
Join Date: September 2001
Location: MK10, UK.
Posts: 4,372
Send a message via MSN to Kaitain Send a message via Skype™ to Kaitain

The database path is fine. Turns out I just needed to swap

Code:
Dim dbRecords As SqlServerCe.SqlCeDataAdapter = Nothing
with

Code:
 Dim dbRecords As New SqlServerCe.SqlCeDataAdapter
Which was shown in the reference but which I missed until my second pint of Ruddles...
__________________
It is by coffee alone I set my mind in motion...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



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

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
AMD launches embedded Fusion chips danrok AMD Motherboards & CPUs 1 20th January, 2011 10:11 PM
Tilera makes 64-core embedded processor danrok General Hardware Discussion 0 22nd August, 2007 02:16 PM
Microsoft Ships SDK For Embedded Applications Gizmo Programming and Assembly Language 0 14th February, 2007 08:27 PM
AOL aims Open AIM SDK at embedded Linux devices Gizmo OS, Software, Firmware, and BIOS 0 18th June, 2006 06:38 PM
Embedded vga controllers or similar... tevildo Mobile Devices and Networking 4 21st April, 2006 01:32 AM


All times are GMT +1. The time now is 04:05 AM.


Copyright ©2001 - 2010, AOA Forums
Don't Click Here Don't Click Here Either

Search Engine Friendly URLs by vBSEO 3.3.0