在項目開發中充分體會到了一個精簡數據存儲模塊的重要性及實用性
在綜合了三年開發經驗的基礎上
向各位推介一下sqlite數據庫
希望更多的程序猿支持開源精神
Imports System
data
SQLite
Public Class Form
Dim conn As SQLiteConnection
Private Sub Button
_Click(ByVal sender As System
Object
ByVal e As System
EventArgs) Handles Button
Click
If System
IO
File
Exists(
test
db
) = True Then
System
IO
File
Delete(
test
db
)
End If
SQLiteConnection
CreateFile(
test
db
)
conn = New SQLiteConnection(
Data Source=test
db
;Pooling=true;FailIfMissing=false
)
If conn
State <> ConnectionState
Open Then
conn
Open()
MsgBox(
打開成功!
)
End If
Dim cmd As New SQLiteCommand
cmd
Connection = conn
cmd
CommandText =
CREATE TABLE Test (ID INTEGER PRIMARY KEY
TestName VARCHAR(
)
TestTime DateTime
Operator VARCHAR(
))
Dim result As Integer = cmd
ExecuteNonQuery()
If result =
Then
MsgBox(
成功
)
Else
MsgBox(
失敗
)
End If
cmd = conn
CreateCommand()
cmd
CommandText =
insert into Test(TestName
TestTime
Operator)values(@Name
@TestTime
@Operator)
cmd
Parameters
Add(
@Name
Data
DbType
String)
Value =
動靜
cmd
Parameters
Add(
@TestTime
Data
DbType
DateTime)
Value = Now()
cmd
Parameters
Add(
@Operator
Data
DbType
String)
Value =
peer
result = cmd
ExecuteNonQuery()
If result <>
Then
MsgBox(
插入成功
)
End If
SelectShowInfo()
cmd = conn
CreateCommand()
cmd
CommandText =
update Test set TestName=
動靜
result = cmd
ExecuteNonQuery()
If result <>
Then
MsgBox(
更新成功
)
End If
SelectShowInfo()
cmd = conn
CreateCommand()
cmd
CommandText =
delete from Test
result = cmd
ExecuteNonQuery()
If result <>
Then
MsgBox(
刪除成功
)
End If
SelectShowInfo()
cmd
Dispose()
If conn
State = ConnectionState
Open Then
conn
Close()
End If
End Sub
Public Sub SelectShowInfo()
Dim sa As New SQLiteDataAdapter(
select * from Test
conn)
Dim ds As New System
Data
DataSet
sa
Fill(ds
Test
)
Dim mytable As New System
Data
DataTable
mytable = ds
Tables(
Test
)
Me
DataGridView
DataSource = mytable
Me
DataGridView
Refresh()
End Sub
End Class
From:http://tw.wingwit.com/Article/program/net/201311/13874.html