INSERT OR REPLACE

INSERT new record or REPLACE existing record if the primary key already exists Command1 = new System.Data.SQLite.SQLiteCommand(Connection1); Command1.CommandText = @"INSERT OR REPLACE INTO tblBookCards (CardId, CardPicture) VALUES (@CardId, @CardPicture)"; Command1.Parameters.AddWithValue("@CardId", CardId); if (BookCardImage.Length > 0) Command1.Parameters.AddWithValue("@CardPicture", BookCardImage); else Command1.Parameters.AddWithValue("@CardPicture", DBNull.Value);    

Read More

DELETE queries

DELETE Example //—– DO DELETE —– Command1 = new System.Data.SQLite.SQLiteCommand(Connection1); Command1.CommandText = @"DELETE FROM tblBookLanguages WHERE LanguageId = @LanguageId"; Command1.Parameters.AddWithValue("@LanguageId", LanguageId); Command1.ExecuteNonQuery();  

Read More

UPDATE queries

UPDATE query example //—– DO QUERY —– Command1 = new System.Data.SQLite.SQLiteCommand(Connection1); Command1.CommandText = @"UPDATE tblBookLanguages SET LanguageText = @LanguageText, LanguageImage = @LanguageImage WHERE LanguageId = @LanguageId"; Command1.Parameters.AddWithValue("@LanguageText", LanguageText); if (LanguageImage.Length > 0) Command1.Parameters.AddWithValue("@LanguageImage", LanguageImage); else Command1.Parameters.AddWithValue("@LanguageImage", DBNull.Value); Command1.Parameters.AddWithValue("@LanguageId", LanguageId); Command1.ExecuteNonQuery();  

Read More

Array Values

Read Array from BLOB column if (Reader1[“LanguageImage”].GetType() != typeof(DBNull)) byte[] LanguageImage = (byte[])Reader1[“LanguageImage”];  

Read More

Null values

Is column returned null? if (Reader1[“LanguageImage”].GetType() != typeof(DBNull)) LanguageImage = (byte[])Reader1[“LanguageImage”]; Set column to null Command1.Parameters.AddWithValue("@LanguageImage", DBNull.Value);  

Read More

INSERT Queries

INSERT Example Command1.CommandText = @"INSERT INTO myTable ( SomeValueColumn, SomeStringColumn ) Values ( @SomeValue, @SomeString )"; //Strings should be added as parameters to avoid sanatisation risks unless you know they are safe. //Other values can be added as parameters too or inline in the INSERT text. Command1.Parameters.AddWithValue("@SomeValue", 1234); Command1.Parameters.AddWithValue("@SomeString", "Hello"); Command1.ExecuteNonQuery(); INSERT and get Auto […]

Read More