研究了下 蛮好用的,比调用excel之类的好用多了
我用的是VS2005
1.引用System.Data.sqlite 如果是VS2005那System.Data.sqlite得版本要选择对应的支持Fwork 2.0的
2,写代码
我把链接数据库改成了类似sqlHelper的类,方便以后引用如Button2的查询
sqlhelper在我的资源里有,大家可以下载
Imports System Imports System.Data.sqlite Imports System.Data Public Class Form1 ' Dim constr As String = "data source= E:\sqlite\mydatabase.sqlite" Dim str As String = Application.StartupPath & "\mydatabase.sqlite" Dim constr As String = "data source= " & str & "" Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click Dim sqlconn As New Data.sqlite.sqliteConnection '定义数据库链接 Dim sqlcmd As New sqlite.sqliteCommand '定义查询操作 Dim ds As New DataSet Dim salda As New sqlite.sqliteDataAdapter Try sqlconn.ConnectionString = constr '链接数据库 sqlconn.Open() sqlcmd.Connection = sqlconn sqlcmd.CommandText = "select * from t_emp" Dim sqlreader As sqlite.sqliteDataReader = sqlcmd.ExecuteReader salda = New sqlite.sqliteDataAdapter(sqlcmd.CommandText,sqlconn) salda.Fill(ds,0) DGV1.DataSource = ds.Tables(0) Finally If Not (sqlconn Is Nothing) Then sqlconn.Dispose() sqlconn = Nothing If Not (salda Is Nothing) Then salda.Dispose() salda = Nothing End Try End Sub Private Sub Button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button2.Click Dim sql As String = "select * from t_emp" Dim ds As DataSet ds = sqliteHelper.ExecuteDataset(constr,CommandType.Text,sql) DGV1.DataSource = ds.Tables(0) End Sub End Class