Represents an open connection to SQLite.
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.
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 VALUES (50,'Development','Philadelphia')";
SQLiteCommand sqCommand = new SQLiteCommand(myInsertQuery);
sqCommand.Connection = myConn;
myConn.Open();
try
{
sqCommand.ExecuteNonQuery();
}
finally
{
myConn.Close();
}
}
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 VALUES (50,'Development','Philadelphia')"
Dim sqCommand As New SQLiteCommand(myInsertQuery)
sqCommand.Connection = myConn
myConn.Open()
Try
sqCommand.ExecuteNonQuery()
Finally
myConn.Close()
End Try
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2