熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

vb.net實現sqlite數據庫編程示例

2022-06-13   來源: .NET編程 
    在項目開發中充分體會到了一個精簡數據存儲模塊的重要性及實用性在綜合了三年開發經驗的基礎上向各位推介一下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
From:http://tw.wingwit.com/Article/program/net/201311/13874.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.