01.
using
Microsoft.VisualBasic;
02.
using
System;
03.
using
System.Collections;
04.
using
System.Collections.Generic;
05.
using
System.Data;
06.
using
System.Diagnostics;
07.
using
System.Data.OleDb;
08.
public
class
Form1
09.
{
10.
string
conStr =
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
+ Application.StartupPath +
"\\DBTest.accdb;Persist Security Info=False;"
;
11.
OleDbConnection con =
new
OleDbConnection();
12.
OleDbCommand cmd =
new
OleDbCommand();
13.
string
sqlStr1;
14.
string
sqlStr2;
15.
private
void
Form1_Load(System.Object sender, System.EventArgs e)
16.
{
17.
con =
new
OleDbConnection(conStr);
18.
}
19.
20.
private
void
Button1_Click(System.Object sender, System.EventArgs e)
21.
{
22.
sqlStr1 =
"INSERT INTO TB1 (Tb1_Name) VALUES ('Test1')"
;
23.
sqlStr2 =
"INSERT INTO TB2 (Tb2_Name) VALUES ('Test2')"
;
24.
con.Open();
25.
26.
cmd =
new
OleDbCommand(sqlStr1, con);
27.
cmd.ExecuteNonQuery();
28.
29.
cmd =
new
OleDbCommand(sqlStr2, con);
30.
cmd.ExecuteNonQuery();
31.
32.
con.Close();
33.
}
34.
public
Form1()
35.
{
36.
Load += Form1_Load;
37.
}
38.
}