当前位置:   article > 正文

C#中使用OleDb操作access数据库_c# oledb

c# oledb

引入oledb类库

using System.Data.OleDb;


//声明连接对象
 private OleDbConnection _oleDbConn;
//Adapter对象
 private OleDbDataAdapter _oleDbAda;
//连接串 包括oledb版本和mdb路径

private String tring_strdata = @"provider=microsoft.jet.oledb.4.0; Data Source=d:\itm\axydeal.mdb";

具体操作:

//实例化、打开连接、读取数据
_oleDbConn = new OleDbConnection(tring_strdata);//根据链接信息实例化链接对象
_oleDbConn.Open();//打开连接;
 string sql = "select * from coininfo where source='Okcoin'";
 OleDbCommand aCommand = new OleDbCommand(sql, _oleDbConn);
 OleDbDataReader dr= aCommand.ExecuteReader();
//OleDbDataReader遍历读取
while (reader.Read())
{
var t1 = reader["字段名"];
}


//插入操作:
string sql = "insert into kline([source],[cointype],[ticks],[datetime],[open],[High],[Low],[close],[Volume])"+
                        " values('okcoincn','ltc_cny','" + ticks + "','2017-8-31 12:23:12','" +open + "','" + high + "','" + low +

                        "','" + close + "','" + volume + "')";

OleDbCommand aCommand = new OleDbCommand(sql, _oleDbConn);

                aCommand.ExecuteNonQuery();


本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/617337
推荐阅读
  

闽ICP备14008679号