vb.net 2003 simple access mdb example? Anywhere?

I bought vb.net back in 2003 and tried working with it for a few days - then uninstalled in disgust and went back to VB6.

I've just decided its time to try out .net again for some database work with an existing access database. I've just spent the entire night searching for an example of just simply opening an access database from a local disk and stuffing some data into a combobox - with absolutely no success.

The samples that (didn't ) come with vb.net don't seem to be accessable on the MS site any more. It keeps throwing me VB2005 upgrade "opportunities", SQL server stuff, and other unrelated things. WHen I did finally find the 2003 "quickstart" examples, the link goes crazy and locks up IE, showing a path with /doc repeated a couple of dozen times...

Does anyone know where I can get a VB2003 example of just opening a plain-jane NON sql-server access 2000 database and stuffing data from that into a combo

Alternatively, can anyone point me to a modern product similar to the old LINEAR VB6 I still cannot understand why MS eliminated basic from its basic language and substituted C++ without the pointers. If I wanted OOP I'd have bought C++ or Java or something.



Answer this question

vb.net 2003 simple access mdb example? Anywhere?

  • mr_c

    How is this,

    VB.NET: An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

    superior to this:

    VB6: Runtime error '-2147217865 (80040e37)'; Table 'account' doesn't exist

    In the VB.net case, I'm left scratching my head with only the vaguest idea where to look. In the VB6 case, I'm told exactly what silly mistake I just made. Its the difference between hours of missing the painfully obvious and 10 seconds to switch to the right database. I don't see how devolving the error reporting feature can be considered progress.

    This disagreement aside, thank you for the example as it is exactly what I needed to get me started! Too often examples are so fleshed out with all sorts of bells and whistlles that its difficult to see the basic idea inside all the code.


  • ferlinco

    Ok, I went back to VB6 and coded the same basic program (open the DB and stuff a combobox. VB6 told me immediately what the problem was - table does not exist in database. Dummy me, the connection as to a different mdb file than what I thought.

    So why is it that ancient old vb6 could just pop up and tell me whats wrong when vb.net could only tell me an exception occured This is what MS considers progress

    I remember upgrading from VB4( ) to VB6. Sure, things were hard to figure out at first but everything was actually *better*. Going from VB6 to vb.net feels like the exact opposite.


  • soanfu

    do you mean getting the data from MS Access and putting it into a combobox if so this almost has it with some modifications to be made for you...

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=868748&SiteID=1

    use OleDb instead of Sql classes so a conversion for you would be this pretty much...import the System.Data.OleDb namespace then...



    Dim theOleDbCommand as new OleDbCommand("SELECT [fieldName] FROM [TableName]", new OleDbConnection(connectionString))
    Dim theDataSet as new DataSet()
    Dim theDataAdapter as new OleDbDataAdapter(theOleDbCommand)
    theDataAdapter.Fill(theDataSet)


    Me.cmbNames.DataSource = theDataSet.Tables(0).DefaultView
    Me.cmbNames.DisplayMember = "FieldName"

    And thats it! You could also do it this way, which would be better in a sense if you are not going to be re-using the dataset for other operations/look ups.


    Dim theOleDbCommand as new OleDbCommand("SELECT [fieldName] FROM [TableName]", new OleDbConnection(connectionString))

    theOleDbCommand.Connection.Open()

    Dim theReader as OleDbDataReader = theOleDbCommand.ExecuteReader(CommandBehavior.CloseConnection)

    while theReader.Read() = true

    Me.theComboBox.Items.Add(theReader(0).ToString())

    end while

    this will read data line by line and add items retrieves from the first column into the combobox.



  • R.Tutus

    What's the inner exception my code was just a snippet example but you should always put try catch blocks around the code to catch any errors and handle them. What is the inner exception thrown I would also suggest placing the square brackets around the fieldname and table name to "escape" from any special meaning the words may have, as I have done in my example

  • PQSIK

    :-) not at all, its good talking about it and sharing views. The platform changes and so does the lifecycle, decisions are made for one reason or another etc.... At least in the .NET, you know exactly where the problem is appearing from in that if its a database problem (oledb) however you should be catching exceptions (or on error goto statements in VB for example). usually you would recieve a JIT giving you the error details on where its coming from, at what line of code, what the specific exception was (inner exception), stack trace etc....

  • gfmajchrzak

    exceptions are pretty much generally runtime errors giving you the specific error that occurs, its better than just having "runtime error 5 type mismatch" errors in VB6

  • bjquinniii

    in what way it will throw a runtime error yes with errors but it would be very unfriendly and unprofessional therefore the try catch blocks are used to handle them, deal with it in your own way and perhaps show the user a more friendly error message in the catch block

  • Penicillin

    Fails a the Dim theRead line with "An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll"

    I'm looking at the error messages and cannot make heads not tails of what is supposed to be wrong other than that it says the oledbcommand = nothing (expected since the dim failed).

    I used the server explorer to create an oledbconnection to an existing access database then copied the connection string from it into the new oledbconnection below, I figure that would be a foolproof way to get the connection string (included password too).

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim theOleDbCommand As New OleDb.OleDbCommand("SELECT name FROM account", New OleDb.OleDbConnection("see above"))

    theOleDbCommand.Connection.Open()

    Dim theReader As OleDb.OleDbDataReader = theOleDbCommand.ExecuteReader(CommandBehavior.CloseConnection) '<< Fails

    While theReader.Read() = True

    Me.thecombobox.Items.Add(theReader(0).ToString())

    End While

    'this will read data line by line and add items retrieves from the first column into the combobox.

    End Sub


  • TigerPhoenix

    I found it easier in VB6 to leave the On Error stuff until after I'd gotten something working as VB6 typically told me enough on its own to let me find and fix the problem. I added the On Error stuff later to prevent ungraceful and/or unnecessary exits.

    Is vb.net not capable of describing errors without user's coding everything in themselves


  • vb.net 2003 simple access mdb example? Anywhere?