VB + SQLite learning records

Source: Internet
Author: User

Reference:

Http://www.sqlite.org/sqlite.html

Http://hi.baidu.com/jt09/blog/item/35f557ae27245cc77dd92aae.html

 

Article 1 (not tested yet)

Register SQLite before programming. The compiled version of litex is sqlite3.5.7.
Regsvr32 sqlite3.dll
You can create a BAT file or run it directly in the Start Menu.
The compressed file package includes the BAT file, sqlite3.dll, test database, and litex development documentation)

Create a table
Dim ODB as object
Set ODB = Createobject ("litex. liteconnection ")
ODB. Open (App. Path & "\ test. DB") 'can be used to directly create a blank File

SQL = "CREATE TABLE tab01 (Name text, NL integar)" 'sqlite database does not need to be defined, but it is easier to define for future transfer or description.
Odb.exe cute (SQL)
ODB. Close

Insert data
Dim ODB as object
Set ODB = Createobject ("litex. liteconnection ")
ODB. Open (App. Path & "\ test. DB ")

SQL = "insert into tab01 values ('chen', 5 )"
Odb.exe cute (SQL)
ODB. Close

Query
Dim ODB as object
Set ODB = Createobject ("litex. liteconnection ")
ODB. Open (App. Path & "\ test. DB ")

Dim odb1 as object
Set odb1 = Createobject ("litex. litestatement ")
Odb1.activeconnection = ODB

Label1 = ""
SQL = "select * From tab01"
Odb1.prepare (SQL)

For each row in odb1.rows use the. Rows attribute to retrieve pre-query data and insert it into label1.
Label1 = label1 & Row (0) & "" & Row (1) & vbcrlf 'in which row is actually an array and the subscript starts from 0
Next

Odb1.close
ODB. Close

'In this document, the status variable odb1 can be directly created using the prepare method of ODB, but I tried it and I don't know why the error is reported, so I changed it to a manual definition, which is the same, which is troublesome.
'I don't know how to define the row variable. It is called litex. literow in the instruction. Later, I tried it and it can be defined as variant. There is no problem in the use process.
'You wanted to dynamically load the DLL file in the program and found the Dynamically Loaded code on the Internet, but I don't know why the error was reported, so I directly registered it in advance.

 

Article 2 (if the test is not completed, you still need to study it)

One of the SQLite databases operated by VB6.0 (dynamic loading of sqlite3.dll)

Http://hi.baidu.com/gantianamin2001/blog/item/d8bf952aba2eb99f033bf6d6.html

 

 

A good operation is to load sqlite3.dll in the program and then operate the database. The sqlite3.dll provided by litex is used.

What are the benefits of doing so?That is obvious, because it is more convenient for programs to dynamically load DLL than to register DLL. The central idea we want to embody is always the simplest user operation. In addition, as far as I am concerned, a large number of DLL registered in the system also feel that there is a lack of aesthetic. if the system is reinstalled, nothing will happen. Isn't it?

Then we only need to use loadlibrary to load it.
To use loadlibrary, We must predefine the loadlibrary method, which is part of the Windows API and must be pre-defined.

Private declare function freelibrary lib "Kernel32" (byval hlibmodule as long) as long
Private declare function loadlibrary lib "Kernel32" alias "loadlibrarya" (byval lplibfilename as string) as long
Private declare function getprocaddress lib "Kernel32" (byval hmodule as long, byval lpprocname as string) as long
Private declare function callwindowproc lib "USER32" alias "callwindowproca" (byval lpprevwndfunc as long, byval hwnd as long, byval MSG as any, byval wparam as any, byval lparam as any) as long

Then it's easy.

Dim LB as long
Lb =Loadlibrary (App. Path & "\ sqlite3.dll ")

Dim ODB as object
Set ODB = Createobject ("litex. liteconnection ")
Textsqliteversion. Text = ODB. Version
ODB. Open (App. Path & "\ test. DB ")

ODB. Execute ("insert into testtable values (2, 'laoma ', 20 )")

Textsqlitechanges. Text = ODB. Changes
Textsqlitepath. Text = ODB. Path

ODB. Close

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.