Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.SQLite
Imports System.Diagnostics
Imports System.Drawing.Printing

Public Class frmAddNew


    Inherits System.Windows.Forms.Form

    'Declaration
    Public Sub Print( _
     ByVal ParamArray args As Object() _
    )
    End Sub
    Public way As String

    

    Function ler_bd() As Boolean

        Dim SQLconnect As New System.Data.SQLite.SQLiteConnection
        Dim SQLcommand As SQLiteCommand
        Dim resultado As System.Data.SQLite.SQLiteDataReader



        On Error GoTo erro
        
        SQLconnect.ConnectionString = "Data Source=.\MyData.db3;"
        SQLconnect.Open()
        SQLcommand = SQLconnect.CreateCommand
        SQLcommand.CommandText = "Select name,type from sqlite_master where type='table'"
        resultado = SQLcommand.ExecuteReader()

        TreeView.Nodes.Clear()
        TreeView.Nodes().Add(way)
        Do While resultado.Read
            Dim novo_nivel As TreeNode = New TreeNode(resultado("name"))

            TreeView.Nodes(0).Nodes.Add(novo_nivel)




        Loop
        TreeView.Nodes(0).Expand()
        resultado.Close()
        SQLconnect.Dispose()
        SQLcommand.Dispose()
        ler_bd = True
        Exit Function
erro:
        MsgBox("Erro Nº " & Err.Number & vbCrLf & Err.Description)
        ler_bd = False

    End Function



    Private Sub TreeView_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView.AfterSelect

        If e.Node.Level > 0 Then
            Dim oWatch As New Stopwatch

            oWatch.Start()

            Dim SQLconnect As New System.Data.SQLite.SQLiteConnection
            Dim dataSet = New DataSet()


            'SQLconnect.ConnectionString = "Data Source=" & way& ";"
            SQLconnect.ConnectionString = "Data Source=.\MyData.db3;"
            SQLconnect.Open()
            Dim dataAdapter = New SQLiteDataAdapter("select * from " & e.Node.Text, SQLconnect)
            dataAdapter.Fill(dataSet, e.Node.Text)


            lblTableName.Text = e.Node.Text
            oWatch.Stop()




        End If
    End Sub



   

    Private Sub lblTableName_TextChanged(sender As System.Object, e As System.EventArgs) Handles lblTableName.TextChanged

    End Sub

    Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub
    Private Sub Principal_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call ler_bd()
    End Sub
	
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles saveBtn.Click


            Dim SQLconnect As New System.Data.SQLite.SQLiteConnection
            Dim dataSet = New DataSet()
			
            


            SQLconnect.ConnectionString = "Data Source=.\MyData.db3;"
            SQLconnect.Open()
            
			'How do I get this to update




        

    End Sub
End Class


What I have tried:

internet search for Examples
So many PDF pages my head is spinning

This works but will not update
Posted
Updated 22-Jan-21 5:22am
v2
Comments
Christian Graus 19-Jan-21 20:56pm    
This code is VB. SQL databases have nothing to do with C#.

Read about ADO.NET and it will help you.

Look at these for C# or VB.NET:
MSDN: ADO.NET[^]
MSDN: Accessing Data with ADO.NET[^]

Our own CodeProject articles (specific to C#):
Using ADO.NET for beginners[^]
Simple ADO.NET Database Read, Insert, Update and Delete using C#.[^]
Beginners guide to accessing SQL Server through C#[^]

Believe these will help you and get started.
 
Share this answer
 
In addition to the suggestions by Sandeep, an alternative may be using this ORM (Object Relational Modeler): SQLite-net[^]

And an even easier alternative might be to use LiteDB:
best-databases-for-a-small-net-application~litedb[^]
 
Share this answer
 
v2
 
Share this answer
 
THANKS looks like I have a lot more reading to do
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900