Access插入数据
private static void AddToDB(IEnumerable<HotelInfo> list) { OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\dbxc.mdb"); OleDbTransaction trans; conn.Open(); trans = conn.BeginTransaction(); OleDbCommand cmd = conn.CreateCommand(); cmd.Transaction = trans; foreach (HotelInfo info in list) { cmd.CommandText = "insert into hotelinfo(url,标题,简介,周围环境,地区查询,开业时间,酒店地址,房间数量,价格信息) values('" + info.url + "','" + info.标题 + "','" + info.简介 + "','" + info.周围环境 + "','" + info.地区查询 + "','" + info.开业时间 + "','" + info.酒店地址 + "','" + info.房间数量 + "','" + info.价格信息 + "')"; cmd.ExecuteNonQuery(); } trans.Commit(); cmd.Dispose(); trans.Dispose(); }