通过OleDB连接方式,访问Access,Excel数据库

文章描述:-2022年2月18日发(作者:十月一上坟)通过OleDB连接方式,访问Access,Excel数据库. OleDbConnectionStringBuilder oleConStr = new OleDbConnectionStringBuilder(); Access 连接信息 tionString = + myDBFileame + ; Excel 连接信息 string myEx

-

通过OleDB连接方式,访问Access,Excel数据库 2022年2月18日发(作者:十月一上坟)


通过OleDB连接方式,访问Access,Excel数据库.
OleDbConnectionStringBuilder oleConStr = new OleDbConnectionStringBuilder();

Access 连接信息
tionString =
+ myDBFileame + ;

Excel 连接信息
string myExcelConStr = + m
yDBFileame + ;

myExcelConStr =
@ +
@ + myDBFileame + +
@ + (34).ToString() +
@ + ExcelConnectionOpti() + (34).To
String();

public bool Headers
{
get { return HasHeaders; }
set { HasHeaders = value; }
}

public bool MixedData
{
get { return IsMixedData; }
set { IsMixedData = value; }
}

private string ExcelConnectionOpti()
{
string strOpts = ;
if (ata == true)
strOpts += ;
if (s == true)
strOpts += ;
else
strOpts += ;
return strOpts;
}

=======查询数据===========
OleDbConnection OleConn = new OleDbConnection(tionStrin


g);
OleDbCommand cmd;
string SqlStr = + newMaTolame + ;
cmd = new OleDbCommand(SqlStr, OleConn);
OleDbDataAdapter OleDapt = new OleDbDataAdapter();
Command = cmd;
();
DataSet myDS = new DataSet();
(myDS);
注意:如果是Excel数据库需在表名后加;

=======增加字段===========
SqlStr = + e(,) +
d decimal,Rowo long IDETITY(1,1) ;
cmd = new OleDbCommand(SqlStr, OleConn);
int affectRows = eonQuery();

=======在DataSet表中增加一列=======
myDS 是已保存有数据的DataSet
if ([0]. < 1)
{
return IsSuccess;
}

DataTable dt = [0];

DataColumn dc = new DataColumn();
pe = e();

tValue = 1;
ame = ;
(dc);
给该列赋值
for (int i = 0; i < ; i++)
{
[i][] = myMaTolame;
}
Changes();

=======获取数据源的框架信息,如其中的表名等.==============
ble dt= DbSchemaTable(OleDbSchemaGuid.
Tables, null);

=======获取与更新 DataGrid中的数据改变,并更新数据源.===============


===========
DataTable dtChanges = nges();
OleDbCommand oleCmd;
OleDbDataAdapter oleda = new OleDbDataAdapter(oleCmd);
Command = new OleDbCommand(strInsert,oleConn);
Command = new OleDbCommand(strUpdate,oleConn);
(dtChanges);


private void CreateewTable()
{

ble table = new DataTable();

DataColumn column;
DataRow row;


column = new DataColumn();
pe = e();
ame = ;
crement = true;
ly = false;
= true;
(column);


column = new DataColumn();
pe = e();
ame = ;
crement = false;
n = ;
ly = false;
tValue = ;
= false;
(column);

设置表的主键
DataColumn[] PrimaryKeyColumns = new DataColumn[1];
PrimaryKeyColumns[0] = s[];
yKey = PrimaryKeyColumns;
Changes();

-

通过OleDB连接方式,访问Access,Excel数据库

发布时间:2022-02-18 21:00:15
文章版权声明:除非注明,否则均为IT技术网-学习WEB前端开发等IT技术的网络平台原创文章,转载或复制请以超链接形式并注明出处。

发表评论

评论列表 (有 14 条评论,244人围观)

最近发表

随便看看

热门文章

标签列表