Results 1 to 2 of 2

Thread: [RESOLVED] I need help with an error message

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    104

    Resolved [RESOLVED] I need help with an error message

    Hello Everyone:

    I am new in programming and I am using vb2005, I am trying to connect to an MS Access database and I am getting an erro message on the following line of code:
    Code:
    searchtable_command = New SqlClient.SqlCommand(searchtable_string, testsearch_connection)
    Error:'System.Data.Odbc.OdbcConnection' cannot be converted to 'System.Data.SqlClient.SqlConnection'.

    Here my connection string:
    Code:
    Dim testsearch_connection As New Odbc.OdbcConnection("Provider=MSDASQL;Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\CesarAccessdatabase.mdb;Uid=admin;Pwd=;")
    What am I missing?

    Thank you so much for your help
    BK

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: I need help with an error message

    You can't mix and match Data namespaces. If you create an OdbcConnection then you can only use it with OdbcCommands. SqlCommands are only for use with SqlConnections.

    SqlClient classes are only for connecting to SQL Server. While you can use Odbc to connect to Access, I would suggest using OleDb, i.e. an OleDbConnection and an OleDbCommand. The connection string will change if you do so visit www.connectionstrings.com for the new format.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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