none
Calling an Access 2003 query from .NET using OLEDB

    Question

  • Hi all of you,

    I am trying to call an Access 2003 query from one  Vb .Net 2.0 console app and I get this message (I think it's not necessary translate into english) : Instrucción SQL no válida; se esperaba 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT' o 'UPDATE'.

    Formerly I was using directly DML stuff: (select * from ... )

     

    How can I work out?

    here you have the snippet of code:

     

    Dim sSql As String = String.EmptyDim miCom As New OleDbCommand

    Dim param As OleDbParameter

    Dim sFichero As String = String.Empty

     

    sconecta.ConnectionString = sCadenaconexion

    sconecta.Open()

     

     

    Dim dInicio As Date = System.DateTime.Now.AddDays(-12).ToString.Substring(0, 10)

    Dim dFin As Date = System.DateTime.Now.ToString.Substring(0, 10)

     

    My.Computer.FileSystem.WriteAllText(sRutaLog & nombre_log, System.DateTime.Now.ToString & " (Proceso: " & System.Reflection.MethodBase.GetCurrentMethod.Name() & ") ->Criterios de fecha. Inicio: " & dInicio & " Fin: " & dFin & vbCrLf, True)

     

     

            'sSql = "SELECT  [NC - DENEGACIONES].[DT-NIDN] + [NC - DENEGACIONES].[DT-NIDL], " & _

            '        "FROM [NC - DENEGACIONES] INNER JOIN [NC - PROVINCIA]  ON  [NC - DENEGACIONES].[DT-PROV] =  [NC - PROVINCIA].COD " & _

            '        "WHERE RESULT <> 'Incidencia interna HJS (RVAD11)' AND [NC - DENEGACIONES].FECHAINSERCION Between ? AND ? "

     

            sSql = "NEXEA_data15"

     

            param = New OleDbParameter()

            param.DbType = DbType.Date

     

            param.Value = New DateTime(dInicio.Year, dInicio.Month, dInicio.Day)

            miCom.Parameters.Add(param)

     

            param = New OleDbParameter()

            param.DbType = DbType.Date

            param.Value = New DateTime(dFin.Year, dFin.Month, dFin.Day)

     

            miCom.Parameters.Add(param)

            miCom.Parameters.Add(New OleDbParameter())

     

            miCom.Connection = sconecta

            miCom.CommandText = sSql

            miCom.CommandType = CommandType.Text

     

            sFichero = Generar_FicheroTXT(miCom.ExecuteReader())

     

     

    TIA


    enr

    Thursday, May 10, 2012 12:00 PM

Answers

  • The anser is Yes! Yes! Yes!

    Yo don't have a valid SQL statement.  A SQL will have different clauses consisting of a SELECT","FROM, and "WHERE".  YOu have commenting all these out of your code.  the error message just is tellign you that you don't havve a VALID SQL

    'sSql = "SELECT  [NC - DENEGACIONES].[DT-NIDN] + [NC - DENEGACIONES].[DT-NIDL], " & _

            '        "FROM [NC - DENEGACIONES] INNER JOIN [NC - PROVINCIA]  ON  [NC - DENEGACIONES].[DT-PROV] =  [NC - PROVINCIA].COD " & _

            '        "WHERE RESULT <> 'Incidencia interna HJS (RVAD11)' AND [NC - DENEGACIONES].FECHAINSERCION Between ? AND ? "

     

            sSql = "NEXEA_data15"

    Try this instead

            sSql = "SELECT * FROM NEXEA_data15"


    jdweng

    • Marked as answer by Enric Vives Thursday, May 10, 2012 1:01 PM
    Thursday, May 10, 2012 12:56 PM

All replies

  • The anser is Yes! Yes! Yes!

    Yo don't have a valid SQL statement.  A SQL will have different clauses consisting of a SELECT","FROM, and "WHERE".  YOu have commenting all these out of your code.  the error message just is tellign you that you don't havve a VALID SQL

    'sSql = "SELECT  [NC - DENEGACIONES].[DT-NIDN] + [NC - DENEGACIONES].[DT-NIDL], " & _

            '        "FROM [NC - DENEGACIONES] INNER JOIN [NC - PROVINCIA]  ON  [NC - DENEGACIONES].[DT-PROV] =  [NC - PROVINCIA].COD " & _

            '        "WHERE RESULT <> 'Incidencia interna HJS (RVAD11)' AND [NC - DENEGACIONES].FECHAINSERCION Between ? AND ? "

     

            sSql = "NEXEA_data15"

    Try this instead

            sSql = "SELECT * FROM NEXEA_data15"


    jdweng

    • Marked as answer by Enric Vives Thursday, May 10, 2012 1:01 PM
    Thursday, May 10, 2012 12:56 PM
  • Joel,

    Great! thanks a lot, I was, suppose, thinking in our dearest RDBMS, MS SQL..


    enr

    Thursday, May 10, 2012 1:04 PM