2011年11月8日 星期二

Connecting SQLite with VB.net

引用來源
--
 Imports System.Data
Imports System.Data.SQLite
Public Class frmDB
    Dim cons As New SQLite.SQLiteConnection
    Dim cmd As New SQLite.SQLiteCommand
    Dim sql As String
    Dim strSQL As String
    Dim dss As New DataSet
    Dim das As New SQLite.SQLiteDataAdapter
    Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
        SQLiteConnection.CreateFile("C:\SQLite_VB.net_Test\mydatabase.db")
        cons.ConnectionString = "Data Source=C:\SQLite_VB.net_Test\mydatabase.db; Version=3"
        strSQL = "create table Ramya(Elename varchar(50))"
        cons.Open()
        das = New SQLite.SQLiteDataAdapter(strSQL, cons)
        das.Fill(dss, "ramya")
        cons.Close()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        cons.ConnectionString = "Data Source=C:\SQLite_VB.net_Test\mydatabase.db; Version=3"
        cons.Open()
        cmd = cons.CreateCommand()
        cmd.CommandText = "INSERT INTO Ramya VALUES('Microsoft')"
        cmd.CommandType = CommandType.Text
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        cons.Close()
        MsgBox("New record added to the database")
    End Sub
End Class

沒有留言:

張貼留言