Results 1 to 14 of 14

Thread: RESOLVED: Learning databases, problem with tutorial: VB.NET 2005

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    34

    Question RESOLVED: Learning databases, problem with tutorial: VB.NET 2005

    I'm trying to get the hang of .NET databases, after having a decent grasp of them in VB 5.0. It's a new animal, though, so I'm starting with a fresh mindset.

    I found this tutorial by Mendhak,
    http://www.vbforums.com/showthread.p...8-Tutorial-%29
    but when I try it, I get an error

    Error 2 Name 'conn' is not declared. ...

    which seems to refer to the line in the tutorial

    conn.connectionstring = "provider=microsoft.jet.oledb.4.0;datasource=c:\sample.mdb;user=Admin;password=;"

    so I inserted this line just above it:

    Dim conn As New OleDbConnection 'trying to declare "conn" to clear an error

    Which clears that error, but on trying to run/debug (page 2 of tutorial) I get an error which highlights the line

    da.Fill(ds)

    The entire code section looks like this:

    Imports System.Data.OleDb
    Public Class Form1
    Dim ds As New DataSet
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim conn As New OleDbConnection 'trying to declare "conn" to clear an error
    conn.ConnectionString = "provider=microsoft.jet.oledb.4.0;datasource=c:\sample.mdb;user=Admin;password=;"
    Dim strsql As String = "select employeeID, FirstName, LastName, Location from tbl_master"
    Dim da As New OleDbDataAdapter(strsql, conn)
    da.Fill(ds)
    If ds.Tables(0).Rows.Count > 0 Then
    TextFirst.Text = ds.Tables(0).Rows(0).Item("FirstName").ToString()
    TextFirst.Text = ds.Tables(0).Rows(0).Item("LastName").ToString()
    TextFirst.Text = ds.Tables(0).Rows(0).Item("Location").ToString()
    TextFirst.Text = ds.Tables(0).Rows(0).Item("EmployeeID").ToString()
    End If
    End Sub
    End Class


    I did download the sample.mdb file, and placed it at c:\sample.mdb, as I have referenced it above.

    Any advice or comments would be welcome.
    Last edited by Og_ofthejungle; Nov 27th, 2012 at 09:10 PM. Reason: RESOLVED by using VBA instead

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Learning databases, problem with tutorial: VB.NET 2005

    da.Fill(ds, t) where t is the name of the table to fill in the dataset (doesn't have to be the same name as in the database but it's usually easier to remember what you're doing if it is).
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Learning databases, problem with tutorial: VB.NET 2005

    well, congrats on figuring out the solution to the first problem. As for your current problem, I suspect that you have eels in your hovercraft. Since there isn't a description of the error, I can only assume one of two things: 1 - you've got eels, or 2 - your fingers fell off and you can't type what the error was.

    -t
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Learning databases, problem with tutorial: VB.NET 2005

    While what dunfiddlin is suggesting is a good idea, it's not actually required and won't be the cause of the error. You can fill a table in a DataSet without naming it and the fact that you later access that table by index rather than name means that a name is not required. I'm guessing that it's actually an issue with your SQL code not being valid for some reason. I'm not sure that Location is a keyword but, if it is, that would do it. If it's not then most likely you don't have that table or those columns in the database. As tg says though, if you give us the error message then we wouldn't have to guess. The error message is provided as a diagnostic aid so, if you'd like us to help diagnose the issue, you should provide it to us.

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    34

    Re: Learning databases, problem with tutorial: VB.NET 2005

    Quote Originally Posted by techgnome View Post
    well, congrats on figuring out the solution to the first problem. As for your current problem, I suspect that you have eels in your hovercraft. Since there isn't a description of the error, I can only assume one of two things: 1 - you've got eels, or 2 - your fingers fell off and you can't type what the error was.

    -t
    I likely have eels.

    The stated error was singularly unhelpful: "Oledb Exception Unhandled."
    On clicking "More Details" I get " {Could not find installable ISAM} "

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    34

    Re: Learning databases, problem with tutorial: VB.NET 2005

    Quote Originally Posted by jmcilhinney View Post
    While what dunfiddlin is suggesting is a good idea, it's not actually required and won't be the cause of the error. You can fill a table in a DataSet without naming it and the fact that you later access that table by index rather than name means that a name is not required. I'm guessing that it's actually an issue with your SQL code not being valid for some reason. I'm not sure that Location is a keyword but, if it is, that would do it. If it's not then most likely you don't have that table or those columns in the database. As tg says though, if you give us the error message then we wouldn't have to guess. The error message is provided as a diagnostic aid so, if you'd like us to help diagnose the issue, you should provide it to us.
    I apologize for the oversight. It seemed very generic to me, and so I dismissed it/forgot it without thinking that it might make sense to others. My error.

    If I were to take dunfiddlin's advice, would I need to first declare t, such as
    dim t as new datatable
    ?

    On edit:
    da.fill(ds,t) 'returns a compile error that t is not declared, so that answers that question;

    dim t as new datatable
    da.fill(ds,t) 'returns a compile error to the effect that no method "fill" can do the requested task

    Dim t As String = "x"
    da.Fill(ds, t) 'returns the same error during runtime, that an Oledb exception is unhandled; no installable ISAM is available.
    Last edited by Og_ofthejungle; Oct 11th, 2012 at 07:37 PM.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Learning databases, problem with tutorial: VB.NET 2005

    This sounds like it's likely a very common problem. You're using the Jet OLE DB provider to connect to the MDB data file and that's only available in 32-bit form. If your project is targeting the Any CPU paltform and you're developing on a 64-bit system then your app will be running in 64-bit mode. As such, as far as it's concerned, there is no Jet OLE DB provider. In that case, you'll need to change the target to x86, to force the app to run in 32-bit mode on all systems. If you're using VS then that's straightforward in the project properties. If you're using VB Express then it's a bit more complex but you can find instructions online.

    On another note, may I ask why you're using such an outdated version of VB? VB 2005 has been superseded three times, by VB 2008, VB 2010 and now VB 2012. Unless you're required to use VB 2005 by some course or the like then I'd suggest that you should at least be using VB 2010. I'd strongly suggest using VB 2012 though, especially since it can round-trip VB 2010 projects to retain compatibility with other developers who are still using VB 2010. VB 2010 and later will set the target platform to x86 for a Win Forms App project by default.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Learning databases, problem with tutorial: VB.NET 2005

    Quote Originally Posted by Og_ofthejungle View Post
    If I were to take dunfiddlin's advice, would I need to first declare t, such as
    dim t as new datatable
    ?
    No, the second parameter is the name of a DataTable, i.e. a String, not an actual DataTable. If the DataSet doesn't already contain a DataTable with that name then one is created.

    Also, DataSets tend to get grossly overused. They are basically a container for DataTables. Unless you have multiple DataTables there's generally no point using a DataSet at all. If you're creating the objects in code then you can just create a DataTable directly and pass that to Fill. Even if you do have multiple DataTables, the DataSet may still not offer any advantage unless you have DataRelations between them.

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    34

    Re: Learning databases, problem with tutorial: VB.NET 2005

    Quote Originally Posted by jmcilhinney View Post
    This sounds like it's likely a very common problem. You're using the Jet OLE DB provider to connect to the MDB data file and that's only available in 32-bit form. If your project is targeting the Any CPU paltform and you're developing on a 64-bit system then your app will be running in 64-bit mode. As such, as far as it's concerned, there is no Jet OLE DB provider. In that case, you'll need to change the target to x86, to force the app to run in 32-bit mode on all systems. If you're using VS then that's straightforward in the project properties. If you're using VB Express then it's a bit more complex but you can find instructions online.

    On another note, may I ask why you're using such an outdated version of VB? VB 2005 has been superseded three times, by VB 2008, VB 2010 and now VB 2012. Unless you're required to use VB 2005 by some course or the like then I'd suggest that you should at least be using VB 2010. I'd strongly suggest using VB 2012 though, especially since it can round-trip VB 2010 projects to retain compatibility with other developers who are still using VB 2010. VB 2010 and later will set the target platform to x86 for a Win Forms App project by default.
    I found VB.net 2005 available at a reasonable price, and I wanted to buy a full version (i.e. not an express or "Learning Edition" so that I could be certain that it would compile stand-alone executables.

    I am running on an XP platform, in 32-bit, so I'm baffled by the error.

  10. #10

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    34

    Re: Learning databases, problem with tutorial: VB.NET 2005

    Good Morning, BTW.

    On Edit:
    I am able to test the database connection successfully, which is my best result with databases to date.

    Where would I look for an option to force x86 only?
    Last edited by Og_ofthejungle; Oct 11th, 2012 at 07:59 PM.

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Learning databases, problem with tutorial: VB.NET 2005

    Quote Originally Posted by Og_ofthejungle View Post
    I found VB.net 2005 available at a reasonable price, and I wanted to buy a full version (i.e. not an express or "Learning Edition" so that I could be certain that it would compile stand-alone executables.
    If that was your reason then you wasted your money because Express editions can compile stand-alone executables and there's no restrictions on their distribution. Express editions do have limitations, certainly, but they'd only be an issue for the most serious of hobbyists.
    Quote Originally Posted by Og_ofthejungle View Post
    I am running on an XP platform, in 32-bit, so I'm baffled by the error.
    I'm not sure either then. I have to admit, I'd have expected a different error message if it was a 32-bit/64-bit issue. I have seen that specific error message before but with varies causes and I can't recall any specifically right now. You could search online and see what solutions other people have used when they encounter that error message.

  12. #12
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: Learning databases, problem with tutorial: VB.NET 2005

    I am interested in learning database programming, so your link to the tutorial piqued my curiosity.

    In your connection string, I think there should be a space in Data Source and an Id in User Id.

    Also, you are writing data from four different fields into the same TextBox (TextFirst).

    I should add; when you post code, if you wrap it in [CODE] [/CODE] or [HIGHLIGHT=vb.net] [/HIGHLIGHT] tags, it is easier to read and easier for people to spot mistakes. There are buttons that aid in doing this that can be found above the post message text area if you select the Go Advanced option.

  13. #13

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    34

    Re: Learning databases, problem with tutorial: VB.NET 2005

    you are correct. I cut and pasted. I should have edited them aftr but I was more concrned with getting the database working. I did check out the string and it looked right but I'll try it the other way.

  14. #14

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    34

    Resolved RESOLVED: Learning databases, problem with tutorial: VB.NET 2005

    Resolution: I built the database in an excel spreadsheet, disguised it as a form, and then used VBA to make it record on the next sheet, and analyze the data for output on the third sheet.

    Works mostly ok.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width