Sinisterly
Bad SQLite Example [C#] - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework)
+--- Thread: Bad SQLite Example [C#] (/Thread-Bad-SQLite-Example-C)



Bad SQLite Example [C#] - nikey646 - 01-19-2014

Been messing around with Mono recently, and decided to see if i could somehow get System.Data.SQLite to work. Turns out i couldn't ^_^

Anyways that resulted with me having a Working C# SQLite Reader.
Add a reference to System.Data.SQLite.dll to the project, and then add
Code:
using System.Data.SQLite;
to the top of the project.

Create a SQLite Database named "dud.sq3", with a table named "a", and 2 rows, i (Interger Primary Auto Increment), b (Numeric), and put it in the Debug folder.

Add a listbox named listBox1 to the form, and then In The Initialization Area, under InitializeComponent();, add:
Code:
var ConnStr = "Data Source={0};version=3;New={1};Compress={2}";

var Dud = new SQLiteConnection
{
    ConnectionString = string.Format(ConnStr, Path.Combine(Application.StartupPath, "dud.sq3"),false,false)
};

using (var Query = new SQLiteCommand())
{
    Dud.Open();

    Query.Connection = Dud;
    Query.CommandText = string.Format("SELECT * FROM {0}", "a");

    var DudReader =  Query.ExecuteReader();

    while (DudReader.Read())
    {
        listBox1.Items.Add(DudReader.GetValue(1).ToString());
    }

    Dud.Close();
}

If any decent C# programmer thinks this code is complete crap, i won't blame them Tongue Still actually learning C#, originally a VB.Net programmer.