See Also

SQLiteConnection Members  | Devart.Data.SQLite Namespace  | SQLiteDataAdapter Class  | SQLiteCommand Class

Language

Visual Basic

C#

Show All

See AlsoLanguagesDevart.Data.SQLiteSend comments on this topic.

SQLiteConnection Class

Devart.Data.SQLite Namespace : SQLiteConnection Class

Represents an open connection to a SQLite database.

For a list of all members of this type, see SQLiteConnection members.

Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Data.Common.DbConnection
            Devart.Common.DbConnectionBase
               Devart.Data.SQLite.SQLiteConnection

Syntax

[Visual Basic]
Public Class SQLiteConnection    Inherits DbConnectionBase
[C#]
public class SQLiteConnection : DbConnectionBase

Remarks

A SQLiteConnection object represents a unique connection to the SQLite database. Use it in conjunction with SQLiteCommand, SQLiteDataReader, SQLiteDataAdapter or other components for convenient interoperation with SQLite database.

When you create an instance of SQLiteConnection, all properties are set to their initial values. For a list of these values, see the _ctor constructor.

If the SQLiteConnection goes out of scope, it is not closed. Therefore, you must explicitly close the connection by calling Close.

Note that SQLiteConnection instance is not guaranteed to be thread safe. You should avoid using the same SQLiteConnection in several threads at the same time. It is recommended to open a new connection per thread and to close it when the work is done. Actually, connections will not be created/disposed every time with the Pooling=true; connection string option - connections will be stored at connection pool. This boosts performance greatly.

A single SQLiteConnection can be used by many SQLiteCommand objects on the assumption that all operations will be done consecutively. In other words, you can not execute a SQL statement while an asynchronous operation is in progress.

This class supports cross-form data binding with the InterForm Technology.

Example

The following example creates a SQLiteCommand and a SQLiteConnection. The SQLiteConnection is opened and set as the Connection property. The example then calls ExecuteNonQuery method, and closes the connection. To accomplish this, the ExecuteNonQuery is passed a connection string and a query string that is SQL INSERT statement.

[C#] 

public void InsertRow(string sqConnectionString) 

  // If the connection string is empty, use default. 
  if(sqConnectionString == "") 
  { 
    sqConnectionString =  
        "DataSource=mydatabase.db"; 
  } 
  SQLiteConnection myConn = new SQLiteConnection(sqConnectionString); 
  string myInsertQuery = "INSERT INTO Dept(DeptNo, DName) Values(50, 'DEVELOPMENT')"; 
  SQLiteCommand sqCommand = new SQLiteCommand(myInsertQuery); 
  sqCommand.Connection = myConn; 
  myConn.Open(); 
  try 
  { 
    sqCommand.ExecuteNonQuery(); 
  } 
  finally 
  { 
    myConn.Close(); 
  } 

[Visual Basic] 

Public Sub InsertRow(sqConnectionString As String)
  ' If the connection string is empty, use default.
  If sqConnectionString = "" Then
    sqConnectionString = _
        "DataSource=mydatabase.db"
  End If
  Dim myConn As New SQLiteConnection(sqConnectionString)
  Dim myInsertQuery As String = "INSERT INTO Dept(DeptNo, DName) Values(50, 'DEVELOPMENT')"
  Dim sqCommand As New SQLiteCommand(myInsertQuery)
  sqCommand.Connection = myConn
  myConn.Open()
  Try
    sqCommand.ExecuteNonQuery()
  Finally
    myConn.Close()
  End Try
End Sub

See Also

SQLiteConnection Members  | Devart.Data.SQLite Namespace  | SQLiteDataAdapter Class  | SQLiteCommand Class

 

 


© 2008 - 2014 Devart. All Rights Reserved.