見下面的代碼,自己換成真實的數(shù)據(jù)庫及表即可
ImportsSystem.Data
ImportsSystem.IO
ImportsSystem.Data.OleDb
ModuleModule1
Publiccn1AsNewOleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\ACCESS數(shù)據(jù)庫1.mdb")'定義連接1---這里請更改為實際數(shù)據(jù)庫路徑及名稱
Publiccn2AsNewOleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\ACCESS數(shù)據(jù)庫2.mdb")'定義連接2---這里請更改為實際數(shù)據(jù)庫路徑及名稱
PublicDataBaseRST1AsInteger'用來返回數(shù)據(jù)庫執(zhí)行結果
PublicDataBaseRST2AsInteger'用來返回數(shù)據(jù)庫執(zhí)行結果
PublicFunctionDataModify(ByValstr_cmd1AsString,ByValstr_cmd2AsString)AsBoolean'進行數(shù)據(jù)庫修改操作函數(shù)
Dimcmdinsert1AsNewOleDbCommand
Dimcmdinsert2AsNewOleDbCommand
Try
cmdinsert1.CommandText=str_cmd1
cmdinsert2.CommandText=str_cmd2
cmdinsert1.Connection=cn1
cmdinsert2.Connection=cn2
Ifcn1.State=ConnectionState.ClosedThencn1.Open()
Ifcn2.State=ConnectionState.ClosedThencn2.Open()
DataBaseRST1=cmdinsert1.ExecuteNonQuery()'用來返回執(zhí)行的結果
DataBaseRST2=cmdinsert2.ExecuteNonQuery()'用來返回執(zhí)行的結果
cn1.Close()
cn2.Close()
ReturnTrue
CatchexAsException
MessageBox.Show(Err.Description,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error)
ReturnFalse
EndTry
EndFunction
EndModule
PublicClassForm1
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
DataModify("insertintoaavalues('1','2')","insertintoaavalues('1','2')")'調(diào)用方法
EndSub
EndClass