- ImportsSystem.Data
- '引入数据库操作类命名空间
- ImportsSystem.Data.OleDb
- '引入ADO.NET操作命名空间
- DimMyConnectionAsNewOleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;DataSource="&Application.StartupPath&"/Book.mdb")'连接数据库
- DimMyCommandAsOleDbCommand'执行命令
- DimMyReaderAsOleDbDataReader'读取数据
- DimsqlAsString="SELECT略……"
- Try'错误时处理
- MyConnection.Open()'连接数据库
- MyCommand=NewOleDbCommand(sql,MyConnection)
- MyCommand.ExecuteNonQuery()'执行sql代码
- CatchcAsException
- MsgBox(c.ToString,MsgBoxStyle.OkOnly,"错误")
- EndTry
- MyConnection.Close()'关闭
- MyCommand.Dispose()'删除