先介绍一下data.OleDb中提供的类:
OleDbconnection conn=new OleDbconnection("str");对于OleDbconnection类,我们通过它和sql语句对数据库文件连接。
例子:
string str1 = Application.StartupPath;//定位运行的程序所在的文件目录
string str = "provider=Microsoft.Jet.OLEDB.4.0; data Source="+str1+@"\telephone.mdb; Persist Security Info=False";
OleDbConnection conn = new OleDbConnection(str);
这样我们就可以通过conn对象来获取数据库信息了。
datacommand类,我们通过datacommand数据库命令对象对数据库的信息进行sql语句操作。
例子:
string str="provider=Microsoft.Jet.OLEDB.4.0; data Source=D:/Student.mdb; Persist Security Info=False";
OleDbConnection conn = new OleDbConnection(str);
string SQLstr = "insert into StudentInfo values(6,'09015','张川','软件工程','软件092班','江苏','0')";
OleDbCommand comm = new OleDbCommand(SQLstr, conn);
try
{
conn.Open();
int i = comm.ExecuteNonQuery();//command的