using System;
using SystemData;
using SystemDataOleDb;
namespace ConsoleDataSet
{
/// <summary>
/// Class 的摘要说明
/// </summary>
class DataSetClass
{
/// <summary>
/// 应用程序的主入口点
/// </summary>
[STAThread]
static void Main(string[] args)
{
string strCon = @Provider=MicrosoftJetOLEDB;Data Source=DataBasemdb;
// 定义连接
OleDbConnection MyCon = new OleDbConnection(strCon);
try
{
// 打开连接
MyConOpen();
string strSQL = @select * from ADODemo;
OleDbDataAdapter MyDataAdapter = new OleDbDataAdapter();
MyDataAdapterSelectCommand = new OleDbCommand(strSQL MyCon);
// 将数据填充到DataSet中
DataSet MyDataSet = new DataSet();
MyDataAdapterFill(MyDataSet ADODemo);
// 从DataSet中获取DataTable
DataTable MyDataTable = MyDataSetTables[ADODemo];
// 设置姓名字段不能为空
MyDataTableColumns[姓名]AllowDBNull = false;
// 修改第一行的姓名
MyDataTableRows[][姓名] = 赵六;
MyDataTableRows[][姓名] = 张三;
// 添加一条新记录
DataRow NewRow = MyDataTableNewRow();
NewRow[姓名] = 赵六;
NewRow[年龄] = ;
MyDataTableRowsAdd(NewRow);
foreach (DataRow row in MyDataTableRows)
{
ConsoleWriteLine(姓名:{} 年龄:{} row[姓名]ToString() row[年龄]ToString());
}
// 将DataSet中的数据更新到数据库中
OleDbCommandBuilder MyCommandBuilder = new OleDbCommandBuilder(MyDataAdapter);
MyDataAdapterUpdate(MyDataSet ADODemo);
}
catch (Exception ex)
{
ConsoleWriteLine({} exToString());
}
finally
{
MyConClose();
}
ConsoleReadLine();
}
}
}