SQLite in VB.net - Page 2
       by Austin Andrews aka Templarian  |  3 May 2008

In the previous page, we started looking at some simple database operations you can do using SQLite. In this page, let's continue doing more of the same.

Inserting a Record (Update/Delete)
Just like in all SQL, if you know how to insert a record, you can change the SQL query to update and delete a record. Create another button called btn_insert and add the fallowing code:

Reading Records into a List
What’s the use of putting all this data into a database if you cannot show it off? First create a button called “btn_readrecord”, and a listbox called “lst_records”, place the code below into the button:

 

Reading Tables into a Drop Down
Most projects require multiple tables to store all the relational information. And most of the times the tables are used to organize categories, so a way to find these tables is needed as shown with the code following code example.

But, first, create a button called btn_tables, and a Combo Box called cmb_tables. Once you have done that, then copy and paste the following code:

Writing/Reading a BLOB Image into the Table
I have left actually writing and reading an image out of the examples thus far because it’s optional and easier to explain out of context. With that said, it is hard enough that one would be mad if I left it out. If you are interested to see this included into the other source, it is a highly recommended to download the source example I've provided at the end of this tutorial that is based on the sample code you see here.

For this, simply create a button called btn_insertimage, a button called btn_updateimage, a button called btn_viewimage, and a picture box called pic_viewer. This example creates a database with a table called foo with 2 columns and image BLOB. In the table, one record is inserted and viewable. The image is always entered into where id is equal to 1.

The code is:

Summary
Hopefully with all these code examples and short explanations, you should be better prepared for your future projects that use SQLite.

Download the source for this project. The source example is a fully working database editor for a simple database with an id, title, description, and image fields:

All of which are stored in the databases. It is highly recommended to read through the source of the example. If you have any questions, please post on the forums.

Austin Andrews aka Templarian

1 | 2




SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple.