填充多表(vs2010连接数据库Access2003)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
using System.Data;
using System.Data.OleDb;
OleDbConnection myConn=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Application.StartupPath+"\\First.mdb;");
myConn.Open();
//建立数据集
DataSet thisDataSet=new DataSet();
//建立适配器
OleDbDataAdapter studentAdapter= new OleDbDataAdapter("SELECT * FROM Student",myConn);
OleDbCommandBuilder studentBuilder=new OleDbCommandBuilder(studentAdapter);
OleDbDataAdapter teacherAdapter= new OleDbDataAdapter("SELECT * FROM Teacher",myConn);
OleDbCommandBuilder teacherBuilder=new OleDbCommandBuilder(teacherAdapter);
OleDbDataAdapter genearchAdapter= new OleDbDataAdapter("SELECT * FROM Genearch",myConn);
OleDbCommandBuilder genearchBuilder=new OleDbCommandBuilder(genearchAdapter);
//填充
studentAdapter.Fill(thisDataSet,"Student");
teacherAdapter.Fill(thisDataSet,"Teacher");
genearchAdapter.Fill(thisDataSet,"Genearch");
myConn.Close();