-
Sep 14th, 2016, 03:09 PM
#1
Thread Starter
Addicted Member
using a DataGridView
I have an old Access 97 database with a query that I want to view on a simple form. Ultimately I'd like to give the user options for selecting a range of dates, or filtering for specific field values, etc and it seems like the DataGridView control is the best choice for that.
I've never used this control before, and the tutorials I've Googled want to use a SQL Server database, not the old JET engine or ODBC. Is there a good guide out there somewhere that would show me the basic stuff I need to do to to get data to display on the grid?
Thanks
-
Sep 14th, 2016, 03:33 PM
#2
Re: using a DataGridView
Use the SQL Server examples, but when they use data types that start with SQL (eg: SQLConnection) simply change them to the OLEDB equivalents (eg: OLEDBConnection).
In terms of the connection string, see www.connectionstrings.com for good examples.
-
Sep 15th, 2016, 08:01 AM
#3
Thread Starter
Addicted Member
Re: using a DataGridView
Originally Posted by si_the_geek
Use the SQL Server examples, but when they use data types that start with SQL (eg: SQLConnection) simply change them to the OLEDB equivalents (eg: OLEDBConnection).
In terms of the connection string, see www.connectionstrings.com for good examples.
Thanks very much. So, I followed one of the tutorials and found an Access 97 connection string in your link. But when I try to open the connection, it throws an exception:
ex.Message = "ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
The database definitely exists in the specified path, and I thought the "Provider" specifies the driver?
Code:
Private Function GetDataTable() As DataTable
'
' This Function needs to build the data table.
'
Dim constring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Databases\PM Module Ovens\DBHeiseHandHeld3.mdb;User Id=admin;Password=;"
Dim table As New DataTable
Dim connection As New Odbc.OdbcConnection(constring)
Try
connection.Open()
Dim command As Odbc.OdbcCommand = connection.CreateCommand
command.CommandText = "SELECT * FROM PRESSURE MODULE QUERY"
table.Load(command.ExecuteReader)
command.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
connection.Close()
End Try
Return table
End Function
Or, maybe my Windows 7 machine doesn't have the JET database engine? The target machines will be WinXp, and my project is specified for x86.
-
Sep 16th, 2016, 08:21 AM
#4
Re: using a DataGridView
Unfortunately the error message is a generic and often meaningless "something is wrong with the connection string", but in this case it is actually the driver it is referring to.
Originally Posted by Maylar
I thought the "Provider" specifies the driver?
Nope... they are similar things, but for different types of database connection technology.
Back in the 1990's ODBC was the best option (and that uses Drivers), but since then OLEDB has come along (which uses Providers).
If you have a specific reason to use ODBC then you probably need to set up a Data Source in Control Panel (for each computer that your program runs on), and find a connection string for ODBC.
If you don't have a specific reason to use ODBC then it would probably be best to use OLEDB instead.
Or, maybe my Windows 7 machine doesn't have the JET database engine? The target machines will be WinXp, and my project is specified for x86.
JET is pre-installed on Windows 7 (and I'm pretty sure XP and earlier too), so that shouldn't be a problem.
Using x86 is the right option, as x64 and AnyCPU would cause problems.
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
|