using System;
using System.Data;
using System.Data.OleDb;
namespace ConsoleDataView
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class DataViewClass
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
string strCon = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DataBase.mdb";
// 定义连接
OleDbConnection MyCon = new OleDbConnection(strCon);
try
{
MyCon.Open();
string strSQL = @"select * from ADODemo";
OleDbDataAdapter MyDataAdapter = new OleDbDataAdapter();
MyDataAdapter.SelectCommand = new OleDbCommand(strSQL, MyCon);
DataSet MyDataSet = new DataSet();
MyDataAdapter.Fill(MyDataSet, "ADODemo");
DataTable MyDataTable = MyDataSet.Tables["ADODemo"];
DataView MyDataView = new DataView(MyDataTable,
"年龄 >= 20", // 筛选行的条件
"年龄", // 按照哪个字段来排序
DataViewRowState.CurrentRows);
foreach(DataRowView row in MyDataView)
{
for (int i=0; i<MyDataView.Table.Columns.Count; i++)
Console.WriteLine(row[i] + "/t");
Console.WriteLine("------------------------");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
MyCon.Close();
}
Console.ReadLine();
}
}
}
c#中对数据库的简单操作
最新推荐文章于 2020-02-22 12:31:24 发布