vb.net

位置:IT落伍者 >> vb.net >> 浏览文章

vb.net实现sqlite数据库编程示例


发布日期:2022年04月24日
 
vb.net实现sqlite数据库编程示例
在项目开发中充分体会到了一个精简数据存储模块的重要性及实用性在综合了三年开发经验的基础上向各位推介一下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

上一篇:用VB.NET轻松制作特效窗体

下一篇:如何用VB.NET Timer控件按设定的间隔完成动作