Hi mailinglists,
Please help.

Good Day SQLite Mailing List,
I have a VB.NET 2008 program running on Windows 7 which populates an
SQLite3 database. After updates are made I need to populate a second SQLite
database with some of the tables in the master database (by pressing a
button). As there will be updates to rows, as well as new rows perhaps the
easiest way to populate the second database will be to clear it and
repopulate it (None of the tables will be enormous). Anyway that is in the
future. The first thing I need to do with the second database is ATTACH it
to the first one. This is what I haven't been able to do successfully. I'll
just give you the schema of one of the tables, and the code which I had
hoped would make the connection, and then a tiny query which doesn't work.
The schemas of the source table and the destination table will be the same.
There's no eror message. The code doesn't throw up any errors. It just
doesn't work.

CREATE TABLE [Items] (
  [Category] VARCHAR(50) NOT NULL,
  [Supplier] VARCHAR(50) DEFAULT 'Default',
  [Product Code] VARCHAR(20) NOT NULL,
  [Short Description] VARCHAR(50),
  [Long Description] VARCHAR(1000),
  [Unit Price] INTEGER,
  [Maximum Sample Quantity] INT,
  [Box Price] INTEGER,
  [Box Quantity] INT,
  [Deleted] VARCHAR(5) DEFAULT 'No',
  [Item Image File Path] VARCHAR(100),
  [Last Update] TIMESTAMP,
  CONSTRAINT [sqlite_autoindex_Items_1] PRIMARY KEY ([Product Code]));

Note that this code doesn't really do much but it doesn't work so it's just
a simple example of the problem.

Imports System.IO.StreamReader
Imports System.Globalization
Imports System.Data.SQLite
Imports System.Data
Imports System.IO

Module dbDataLayer
    Public Function SynchroniseDB() As Boolean
        Dim dbConnection As New SQLiteConnection
        Dim dbDataSet As New DataSet
        Dim SQLStmt As String
        Dim sDBPath As String = Application.StartupPath & "\wolfpro.db3"
        Dim sUpdateDBPath As String = Application.StartupPath &
"\UpdateWolfpro.db3"
        Try
            If dbConnection.State = ConnectionState.Closed Then
                dbConnection.ConnectionString = "Data Source=" & sDBPath &
";New=True;Compress=True;Synchronous=Off"
                dbDataSet.Locale = CultureInfo.InvariantCulture
                dbConnection.Open()
                dbDataSet.Reset()
            End If
            SQLStmt = "ATTACH '" & sUpdateDBPath & "' AS UPD"
            Dim dbCmd As New SQLiteCommand(SQLStmt, dbConnection)
            dbCmd.ExecuteNonQuery()
            SQLStmt = "DELETE FROM UPD.Items"
            Dim dbCmd2 As New SQLiteCommand(SQLStmt, dbConnection)
            dbCmd2.ExecuteNonQuery()
            Return True
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Return False
        End Try
    End Function
End Module

-- 
Chris Parsonson
083 777 9261

Reply via email to