【发布时间】:2014-01-22 20:53:18
【问题描述】:
string conString = @"Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=C:\Users\user\Documents\Visual Studio 2010\Projects\Timetable\Timetable\bin\Debug\timetabledata.accdb";
//create the database query
string query = "SELECT * FROM relation";
OleDbConnection conn = new OleDbConnection(conString);
conn.Open();
// create the DataSet
DataSet ds = new DataSet();
// create the adapter and fill the DataSet
OleDbDataAdapter adapter;
adapter = new OleDbDataAdapter(query, conn);
adapter.Fill(ds);
int f = ds.Tables[0].Rows.Count;
int i;
for (i = 0; i < f; i++)
{
// create the database query
string query1 = "SELECT * FROM [time] Where classid= '"+
ds.Tables[0].Rows[i].ItemArray[2]+"'";
DataSet ds1 = new DataSet();
OleDbDataAdapter adapter1;
adapter1 = new OleDbDataAdapter(query1, conn);
adapter1.Fill(ds1);
MessageBox.Show(ds1.Tables[0].Rows[0].ItemArray[0].ToString());
}
我在消息框中得到的结果不是真的,我希望所有行的 id 具有相同的 classid,但在消息框中我只是在继续之前进行验证,我看到时间表的 id 而没有考虑在哪里
【问题讨论】:
-
这里不要假设 SQL 引擎有问题。您在代码中某处做出错误假设的可能性更多。做一些调试来找出什么。检查运行时查询,使用和不使用
WHERE子句对数据库手动运行该查询,检查结果。在不了解您的数据的情况下,我们不可能知道这里的值应该是什么。 -
谢谢..我做了但没有结果..我再试一次
-
我使用“like”而不是“=”,我得到了我想要的结果,但这是真的吗?
标签: c# select oledb where-clause