2
Answers

command.ExecuteReader();

Davood Riazi

Davood Riazi

10y
1.4k
1
when i use this code in my project in vs 2012 and my Database is Access it display an error in this line "  OleDbDataReader reader = command.ExecuteReader();" 

The error is :   " The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect."

what should i do for solving this error ?


Thanks for any help 

Davood


------------------------------

This is my code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Configuration;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string connectionString, queryString;
        
        connectionString = ConfigurationManager.ConnectionStrings["ostanConnectionString"].ToString();
        queryString = "SELECT FROM situation where state ='" + DropDownList1.SelectedValue + "'";
        using (OleDbConnection connection = new OleDbConnection(connectionString))
        {
            OleDbCommand command = new OleDbCommand(queryString, connection);

            connection.Open();
            OleDbDataReader reader = command.ExecuteReader();

            DropDownList2.Items.Clear();
            while (reader.Read())
                DropDownList2.Items.Add(reader["city"].ToString());

            reader.Close();
            connection.Close();
        }
    }
}
Answers (2)