locked
Datareader to access database - Visual Web Developer 2010 RRS feed

  • Question

  • User2095122027 posted

    I am using VB.net to access a .mdb and I get the following error: Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.

    Imports System.Data
    Imports System.Data.OleDb


    Public Class index
        Inherits System.Web.UI.Page

        Protected cnxstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= " & Server.MapPath("app_data\db_bozkaketa.mdb") & ";"
        Protected cnx As New OleDbConnection(cnxstring)
        Protected puestostring As String = "SELECT * FROM votantes"
        Protected cmd As OleDbCommand = New OleDbCommand(cnxstring, cnx)

        Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

            cnx.Open()
            Dim reader As OleDbDataReader = cmd.ExecuteReader()

        End Sub
    End Class

    thanks!

    Wednesday, March 13, 2013 4:57 AM

Answers

  • User522486851 posted

    hi

    proble is you give your connection string as command 

    Protected cmd As OleDbCommand = New OleDbCommand(cnxstring, cnx)

    it should be

    Protected cmd As OleDbCommand = New OleDbCommand(puestostring, cnx)

    fore more detail refer this link

    http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand(v=vs.71).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 13, 2013 5:35 AM
  • User2095122027 posted

    Ok, I realized this was wrong:

    Protected cmd As OleDbCommand = New OleDbCommand(cnxstring, cnx)

    the first argument was not ok, I needed to put the string with the SQL sentence like this:

    Protected cmd As OleDbCommand = New OleDbCommand(puestostring, cnx)

    thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 13, 2013 5:36 AM

All replies

  • User522486851 posted

    hi

    proble is you give your connection string as command 

    Protected cmd As OleDbCommand = New OleDbCommand(cnxstring, cnx)

    it should be

    Protected cmd As OleDbCommand = New OleDbCommand(puestostring, cnx)

    fore more detail refer this link

    http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand(v=vs.71).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 13, 2013 5:35 AM
  • User2095122027 posted

    Ok, I realized this was wrong:

    Protected cmd As OleDbCommand = New OleDbCommand(cnxstring, cnx)

    the first argument was not ok, I needed to put the string with the SQL sentence like this:

    Protected cmd As OleDbCommand = New OleDbCommand(puestostring, cnx)

    thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 13, 2013 5:36 AM