如下列程式碼︰
Using cmd As New OleDbCommand("CREATE TABLE [test] ([ID] INTEGER,[Username] VarChar,[UserPwd] VarChar)", CalcdConnection)
cmd.ExecuteNonQuery()
cmd.CommandText = "INSERT INTO [test$] VALUES(1,'elmer','password')"
cmd.ExecuteNonQuery()
End Using
可寫成如下表示︰
Dim cmd As New OleDbCommand("CREATE TABLE [test] ([ID] INTEGER,[Username] VarChar,[UserPwd] VarChar)", CalcdConnection)
Try
cmd.ExecuteNonQuery()
cmd.CommandText = "INSERT INTO [test$] VALUES(1,'elmer','password')"
cmd.ExecuteNonQuery()
Finally
If cmd <> vbNull Then
cmd.Dispose()
End If
End Try
事實上並不包含錯誤處理,也就是Catch區塊;因此需自行添加錯誤處理方式