在项目开发中充分体会到了一个精简数据存储模块的重要性及实用性
在综合了三年开发经验的基础上
向各位推介一下sqlite数据库
希望更多的程序猿支持开源精神
Imports SystemdataSQLite
Public Class Form
Dim conn As SQLiteConnection
Private Sub Button_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ButtonClick
If SystemIOFileExists(testdb) = True Then
SystemIOFileDelete(testdb)
End If
SQLiteConnectionCreateFile(testdb)
conn = New SQLiteConnection(Data Source=testdb;Pooling=true;FailIfMissing=false)
If connState <> ConnectionStateOpen Then
connOpen()
MsgBox(打开成功!)
End If
Dim cmd As New SQLiteCommand
cmdConnection = conn
cmdCommandText = CREATE TABLE Test (ID INTEGER PRIMARY KEYTestName VARCHAR()TestTime DateTimeOperator VARCHAR())
Dim result As Integer = cmdExecuteNonQuery()
If result = Then
MsgBox(成功)
Else
MsgBox(失败)
End If
cmd = connCreateCommand()
cmdCommandText = insert into Test(TestNameTestTimeOperator)values(@Name@TestTime@Operator)
cmdParametersAdd(@Name DataDbTypeString)Value = 动静
cmdParametersAdd(@TestTime DataDbTypeDateTime)Value = Now()
cmdParametersAdd(@Operator DataDbTypeString)Value = peer
result = cmdExecuteNonQuery()
If result <> Then
MsgBox(插入成功)
End If
SelectShowInfo()
cmd = connCreateCommand()
cmdCommandText = update Test set TestName=动静
result = cmdExecuteNonQuery()
If result <> Then
MsgBox(更新成功)
End If
SelectShowInfo()
cmd = connCreateCommand()
cmdCommandText = delete from Test
result = cmdExecuteNonQuery()
If result <> Then
MsgBox(删除成功)
End If
SelectShowInfo()
cmdDispose()
If connState = ConnectionStateOpen Then
connClose()
End If
End Sub
Public Sub SelectShowInfo()
Dim sa As New SQLiteDataAdapter(select * from Test conn)
Dim ds As New SystemDataDataSet
saFill(ds Test)
Dim mytable As New SystemDataDataTable
mytable = dsTables(Test)
MeDataGridViewDataSource = mytable
MeDataGridViewRefresh()
End Sub
End Class