[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

Access with ODBC from VB 2005

Jaime Lucci

8/25/2006 11:22:00 PM

Hi everyne

I`m trying to run aan acces query with parameters from VB 2005. If I do it
with OleDB components I have no problems, but I need to do that with ODBC,
but I get this error:

ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] Invalid SQL
statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.

The code is the following:

Dim CnnODBC As Odbc.OdbcConnection
Dim cmd As Odbc.OdbcCommand
'Connect to database
CnnODBC = New Odbc.OdbcConnection("DSN=asd")
CnnODBC.Open()
'The ms access query
cmd = New Odbc.OdbcCommand("AgregarCliente", CnnODBC)
cmd.CommandType = CommandType.StoredProcedure
'Parameters
With cmd.Parameters
.Add("paramRazonSocial", txtRazonSocial.Text)
.Add("paramDomicilio", txtDomicilio.Text)
.Add("paramNumCliente", txtNumCliente.Text)
End With
'Execution
cmd.ExecuteNonQuery()
'Disconnect
CnnODBC.Close()

The error occurs in the execute line. Can you help me?

Thanks

Jaime Lucci.



2 Answers

Jim Hughes

8/29/2006 1:21:00 PM

0

The command verbs supported by ODBC are not as rich as those available from
OleDB.

If OleDB works, I would use OleDB.

If it is an issue of connection strings, check out
www.connectionstrings.com.

What SQL statement is contained in AgregarCliente?

Remember that you can not include VBA functions in SQL statements that will
be executed outside of Access.

"Jaime Lucci" <jaimelucci@hotmail.com> wrote in message
news:uXsU40JyGHA.2220@TK2MSFTNGP02.phx.gbl...
> Hi everyne
>
> I`m trying to run aan acces query with parameters from VB 2005. If I do it
> with OleDB components I have no problems, but I need to do that with ODBC,
> but I get this error:
>
> ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] Invalid SQL
> statement; expected ''DELETE'', ''INSERT'', ''PROCEDURE'', ''SELECT'', or
> ''UPDATE''.
>
> The code is the following:
>
> Dim CnnODBC As Odbc.OdbcConnection
> Dim cmd As Odbc.OdbcCommand
> ''Connect to database
> CnnODBC = New Odbc.OdbcConnection("DSN=asd")
> CnnODBC.Open()
> ''The ms access query
> cmd = New Odbc.OdbcCommand("AgregarCliente", CnnODBC)
> cmd.CommandType = CommandType.StoredProcedure
> ''Parameters
> With cmd.Parameters
> .Add("paramRazonSocial", txtRazonSocial.Text)
> .Add("paramDomicilio", txtDomicilio.Text)
> .Add("paramNumCliente", txtNumCliente.Text)
> End With
> ''Execution
> cmd.ExecuteNonQuery()
> ''Disconnect
> CnnODBC.Close()
>
> The error occurs in the execute line. Can you help me?
>
> Thanks
>
> Jaime Lucci.
>
>
>


david @ epsom dot com dot au

9/7/2006 11:49:00 AM

0

You may not be able to connect to a ''stored procedure'' like
that. (I haven''t tried). If that is your problem, you need to
create a ''parameter query'' instead of a ''stored procedure''

Do you know if your mdb is in ''Jet'' mode or ''SQL Server''
mode? Do you know how the query was created? If you
open the mdb in Access 2000, can you see the query
listed in the database window? If so, what is the SQL?

(david)




"Jaime Lucci" <jaimelucci@hotmail.com> wrote in message
news:uXsU40JyGHA.2220@TK2MSFTNGP02.phx.gbl...
> Hi everyne
>
> I`m trying to run aan acces query with parameters from VB 2005. If I do it
> with OleDB components I have no problems, but I need to do that with ODBC,
> but I get this error:
>
> ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] Invalid SQL
> statement; expected ''DELETE'', ''INSERT'', ''PROCEDURE'', ''SELECT'', or
''UPDATE''.
>
> The code is the following:
>
> Dim CnnODBC As Odbc.OdbcConnection
> Dim cmd As Odbc.OdbcCommand
> ''Connect to database
> CnnODBC = New Odbc.OdbcConnection("DSN=asd")
> CnnODBC.Open()
> ''The ms access query
> cmd = New Odbc.OdbcCommand("AgregarCliente", CnnODBC)
> cmd.CommandType = CommandType.StoredProcedure
> ''Parameters
> With cmd.Parameters
> .Add("paramRazonSocial", txtRazonSocial.Text)
> .Add("paramDomicilio", txtDomicilio.Text)
> .Add("paramNumCliente", txtNumCliente.Text)
> End With
> ''Execution
> cmd.ExecuteNonQuery()
> ''Disconnect
> CnnODBC.Close()
>
> The error occurs in the execute line. Can you help me?
>
> Thanks
>
> Jaime Lucci.
>
>
>