关于使用C#读取access数据库记录的问题!
我的代码:stringbasePath=@"D:\Doc\wordcount.mdb";stringconnstr="Provider=Microsoft.Jet.OLE...
我的代码:
string basePath = @"D:\Doc\wordcount.mdb";
string connstr = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=" + basePath;
string sql = "select * from [wordcount]";
List<WordInfo> list = new List<WordInfo>();
using (OleDbConnection conn = new OleDbConnection(connstr))
{
try
{
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
OleDbDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
WordInfo tmp = new WordInfo();
tmp.word = reader.GetString(1);
tmp.flag = 0;
list.Add(tmp);
}
reader.Close();
conn.Close();
}
catch (Exception ex)
{
Console.WriteLine("异常:" + ex.Message);
}
}
数据库表:
我想按照count值的大小,从大到小降序取前500条记录,请问sql语句该怎么写,我初次接触所以不是很了解,请教各位! 展开
string basePath = @"D:\Doc\wordcount.mdb";
string connstr = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=" + basePath;
string sql = "select * from [wordcount]";
List<WordInfo> list = new List<WordInfo>();
using (OleDbConnection conn = new OleDbConnection(connstr))
{
try
{
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
OleDbDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
WordInfo tmp = new WordInfo();
tmp.word = reader.GetString(1);
tmp.flag = 0;
list.Add(tmp);
}
reader.Close();
conn.Close();
}
catch (Exception ex)
{
Console.WriteLine("异常:" + ex.Message);
}
}
数据库表:
我想按照count值的大小,从大到小降序取前500条记录,请问sql语句该怎么写,我初次接触所以不是很了解,请教各位! 展开
2个回答
展开全部
select top 500 * from wordcound1 order by Count desc
追问
请问这个desc是什么。。
追答
排序用的
asc 为升序
desc 为降序
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询