赞
踩
这是源代码
string AccessConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Environment.CurrentDirectory + "\\TestDB.accdb";
string SQLiteConn = "Data Source=" + Environment.CurrentDirectory + "\\Test.db";
float II = 10000;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
LblTotal.Text = "";
}
private void Btn1_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection(AccessConn);
conn.Open();
Lab1.Text = "开始:" + DateTime.Now.ToString("HH:mm:ss-fff");
OleDbCommand Cmd = new OleDbCommand();
Cmd.Connection = conn;
OleDbTransaction tr=conn.BeginTransaction();
Cmd.Transaction = tr;
for(int i=1;i<=II;i++)
{
Cmd.CommandText = "Insert into Test(Sid,Sname) values(" + i + ",'" + i.ToString() + "')";
Cmd.ExecuteNonQuery();
Application.DoEvents();
Lab3.Text = (i / II) * 100 + " %";
}
tr.Commit();
Lab2.Text = "结束:" + DateTime.Now.ToString("HH:mm:ss-fff");
tr.Dispose();
Cmd.Dispose();
conn.Close();
conn.Dispose();
}
private void Btn2_Click(object sender, EventArgs e)
{
ADODB.Recordset rs = new ADODB.Recordset();
ADODB.Connection cn = new ADODB.Connection();
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Environment.CurrentDirectory + "\\TestDB.accdb";
cn.Open();
object dummy;
Lab4.Text = "开始:" + DateTime.Now.ToString("HH:mm:ss-fff");
cn.BeginTrans();
for (int i = 1; i <= II; i++)
{
string aa = "Insert into Test(Sid,Sname) values(" + i + ",'" + i.ToString() + "')";
cn.Execute(aa, out dummy, -1);
Application.DoEvents();
Lab6.Text = (i / II) * 100 + " %";
}
cn.CommitTrans();
Lab5.Text = "结束:" + DateTime.Now.ToString("HH:mm:ss-fff");
cn.Close();
}
private void Btn3_Click(object sender, EventArgs e)
{
// 连接数据库
SQLiteConnection conn = new SQLiteConnection(SQLiteConn);
conn.Open();
Lab7.Text = "开始:" + DateTime.Now.ToString("HH:mm:ss-fff");
// 创建数据表
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = conn;
SQLiteTransaction trans = conn.BeginTransaction();
try
{
for (int i = 1; i <= II; i++)
{
cmd.CommandText = "insert into Test(Sid,Sname) values ("+i+",'"+i.ToString()+"')";
cmd.ExecuteNonQuery();
Application.DoEvents();
Lab9.Text = (i / II) * 100 + " %";
}
trans.Commit();
}
catch
{
trans.Rollback();
throw;
}
Lab8.Text = "结束:" + DateTime.Now.ToString("HH:mm:ss-fff");
conn.Close();
}
private void button1_Click(object sender, EventArgs e)
{
DBEngine dbEngine = new DBEngine();
Database db = dbEngine.OpenDatabase(Environment.CurrentDirectory + "\\TestDB.accdb");
Recordset rs = db.OpenRecordset("Test");
Field[] myFields = new Field[9];
myFields[0] = rs.Fields["ID"];
myFields[1] = rs.Fields["Sid"];
myFields[2] = rs.Fields["Sname"];
label3.Text = "开始:" + DateTime.Now.ToString("HH:mm:ss-fff");
for (int i = 1; i <= II; i++)
{
rs.AddNew();
myFields[1].Value = i;
myFields[2].Value = i.ToString();
rs.Update();
label1.Text = (i / II) * 100 + " %";
}
label2.Text = "结束:" + DateTime.Now.ToString("HH:mm:ss-fff");
rs.Close();
db.Close();
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。