[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
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.