-
Oct 11th, 2012, 05:54 PM
#1
Thread Starter
Member
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
-
Oct 11th, 2012, 06:03 PM
#2
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!
-
Oct 11th, 2012, 06:10 PM
#3
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
-
Oct 11th, 2012, 07:08 PM
#4
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.
-
Oct 11th, 2012, 07:14 PM
#5
Thread Starter
Member
Re: Learning databases, problem with tutorial: VB.NET 2005
Originally Posted by techgnome
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} "
-
Oct 11th, 2012, 07:18 PM
#6
Thread Starter
Member
Re: Learning databases, problem with tutorial: VB.NET 2005
Originally Posted by jmcilhinney
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.
-
Oct 11th, 2012, 07:23 PM
#7
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.
-
Oct 11th, 2012, 07:27 PM
#8
Re: Learning databases, problem with tutorial: VB.NET 2005
Originally Posted by Og_ofthejungle
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.
-
Oct 11th, 2012, 07:42 PM
#9
Thread Starter
Member
Re: Learning databases, problem with tutorial: VB.NET 2005
Originally Posted by jmcilhinney
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.
-
Oct 11th, 2012, 07:48 PM
#10
Thread Starter
Member
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.
-
Oct 11th, 2012, 08:15 PM
#11
Re: Learning databases, problem with tutorial: VB.NET 2005
Originally Posted by Og_ofthejungle
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.
Originally Posted by Og_ofthejungle
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.
-
Oct 11th, 2012, 08:56 PM
#12
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.
-
Oct 12th, 2012, 12:35 AM
#13
Thread Starter
Member
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.
-
Nov 27th, 2012, 09:09 PM
#14
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|