OleDbDataReader reader = command.ExecuteReader(); [英] OleDbDataReader reader = command.ExecuteReader();
问题描述
嗨
当我使用Database Access在vs.net 2012中编译我的网站项目时,它会在此行显示错误OleDbDataReader reader = command.ExecuteReader();
错误是:SELECT语句包含拼写错误或缺失的保留字或参数名称,或者标点符号不正确。
我该怎么做才能解决这个错误?
-------------- ----------------
这是我的代码:
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 :
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();
}
}
}
感谢您的帮助
Davood
Thanks for any help
Davood
推荐答案
嗨Davood,
选择查询语法错误在你的代码中,
从yourTableName WHERE condition1和condition2 OR condition3 <中选择[column_name1],[column_name2] .... [column_name] / code>
更新您的选择查询并试用。
希望这可以帮到你一点。
问候,
RK
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
如果您正在使用SelectedValue,则表示使用国家/地区ID为int
如果int则更改查询:(我已从您的条件中删除单引号)
state =+ DropDownList1。 SelectedValue +
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 + ""
这篇关于OleDbDataReader reader = command.ExecuteReader();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!