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 sqLiteConnectionString)
{
// If the connection string is empty, use default.
if(sqLiteConnectionString == "")
{
sqLiteConnectionString =
"DataSource=mydatabase.db;";
}
SQLiteConnection myConn = new SQLiteConnection(sqLiteConnectionString);
string myInsertQuery = "INSERT INTO DEPT VALUES (50,'Development','Philadelphia')";
SQLiteCommand sqLiteCommand = new SQLiteCommand(myInsertQuery);
sqLiteCommand.Connection = myConn;
myConn.Open();
try
{
sqLiteCommand.ExecuteNonQuery();
}
finally
{
myConn.Close();
}
} |
|
|---|
Public Sub InsertRow(sqLiteConnectionString As String)
' If the connection string is empty, use default.
If sqLiteConnectionString = "" Then
sqLiteConnectionString = _
"DataSource=mydatabase.db;"
End If
Dim myConn As New SQLiteConnection(sqLiteConnectionString)
Dim myInsertQuery As String = "INSERT INTO DEPT VALUES (50,'Development','Philadelphia')"
Dim sqLiteCommand As New SQLiteCommand(myInsertQuery)
sqLiteCommand.Connection = myConn
myConn.Open()
Try
sqLiteCommand.ExecuteNonQuery()
Finally
myConn.Close()
End Try
End Sub |