Click here to Skip to main content
15,904,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
When i compile my web site project in vs.net 2012 with Database Access it displays 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 ?

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

This is my code :

C#
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();
        }
    }
}


Thanks for any help

Davood
Posted
Updated 26-Nov-13 23:24pm
v2

Hi Davood,

Select query syntax is wrong in your code,

Select [column_name1],[column_name2] .... [column_name] from yourTableName WHERE condition1 and condition2 OR condition3

Update your select query and try it.

Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
v2
Comments
davood rz 27-Nov-13 5:32am    
Hi ,
Thanks for your help. it works , but in DropDownList2 it dosen't show anything . why ?
♥…ЯҠ…♥ 27-Nov-13 5:38am    
Try to debug and see what you get in DropDownlist1.SelectedValue....
davood rz 27-Nov-13 6:00am    
in DropDownlist1.SelectedValue it shows province name .but i want whenever i click on DropDownlist1 it shows me the name of province's city in DropDownlist2 .

♥…ЯҠ…♥ 27-Nov-13 6:18am    
I can't get you... can you rephrase it?
If you are taking SelectedValue it means using country ID which is int
if int then change query:(I have removed single quote from your condition)

state =" + DropDownList1.SelectedValue + ""
 
Share this answer
 
Comments
davood rz 27-Nov-13 5:51am    
I did it , but again it displays an error in this line " OleDbDataReader reader = command.ExecuteReader();"

the error is : "No value given for one or more required parameters."

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900