sqlite数据表到DataGridView [英] sqlite datatable to DataGridView

查看:66
本文介绍了sqlite数据表到DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Access数据库中使用了这个脚本,效果很好但是在更改为SQLite后出现了错误:

i used this script with my Access DB and it worked great but after changing to SQLite got an ERROR:

Public Shared Function Con_SQLite(ByVal commandString As String)
        Dim mycon As New SQLiteConnection()

        Try
            mycon.ConnectionString = "data source= " & SQLite_db
            mycon.Open()

            Dim da As New SQLiteDataAdapter(commandString, mycon)
            Dim ds As New DataSet()
            da.Fill(ds)
            Dim dt As DataTable
            dt = ds.Tables(0)
            mycon.Close()

            Return dt

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Function

Dim dt as datatable = Con_SQLite("Select a.c_name  ,b.* from companies a left join D_Year b on a.c_name=b.c_name")


Dim dv As DataView
        dv = New DataView(dt, "b.c_name is null, "a.c_name ", DataViewRowState.CurrentRows)
        DataGridView1.RowHeadersVisible = False
        DataGridView1.DataSource = dv
        DataGridView1.Columns(0).Visible = False
        DataGridView1.Columns(1).HeaderText = "customer"
        DataGridView1.Columns(1).Width = 500
        For i As Integer = 2 To DataGridView1.ColumnCount - 1
            DataGridView1.Columns.Remove(DataGridView1.Columns(2).Name)
        Next

推荐答案

尝试这些修改:

Dim dt as datatable = Con_SQLite(" select b。* from a companies of left join D_Year b on a.c_name = b.c_name")

。 。 。$
dv =新DataView(dt,"c_name为null,"c_name",DataViewRowState.CurrentRows)


这篇关于sqlite数据表到DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆