Results 1 to 4 of 4

Thread: using a DataGridView

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2015
    Location
    Connecticut, USA
    Posts
    147

    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

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2015
    Location
    Connecticut, USA
    Posts
    147

    Re: using a DataGridView

    Quote Originally Posted by si_the_geek View Post
    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.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    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.

    Quote Originally Posted by Maylar View Post
    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
  •  



Click Here to Expand Forum to Full Width