本文整理汇总了C#中Mono.Data.Sqlite.SqliteCommand.ExecuteNonQuery方法的典型用法代码示例。如果您正苦于以下问题:C# SqliteCommand.ExecuteNonQuery方法的具体用法?C# SqliteCommand.ExecuteNonQuery怎么用?C# SqliteCommand.ExecuteNonQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Data.Sqlite.SqliteCommand
的用法示例。
在下文中一共展示了SqliteCommand.ExecuteNonQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteFiles
/// <summary>
/// Write or update files and hashes.
/// </summary>
/// <param name="liste"></param>
public void WriteFiles(List<FileObject> liste)
{
using (SqliteTransaction sqt = connection.BeginTransaction()) {
using (SqliteCommand sqc = new SqliteCommand(connection)) {
// Alle vorhandenen Einträge löschen, da diese in jedem Fall überschrieben werden sollten
sqc.CommandText = "DELETE FROM Files WHERE path=:path";
sqc.Parameters.Add(new SqliteParameter("path"));
foreach (FileObject d in liste) {
sqc.Parameters["path"].Value = d.Filepath;
sqc.ExecuteNonQuery();
}
//sqc.Parameters.Clear(); // Nötig?
// Dateien eintragen
sqc.CommandText = "INSERT INTO Files (path, hash, size, changedate) VALUES (:path, :hash, :size, :changedate)";
sqc.Parameters.Add(new SqliteParameter("path"));
sqc.Parameters.Add(new SqliteParameter("hash"));
sqc.Parameters.Add(new SqliteParameter("size"));
sqc.Parameters.Add(new SqliteParameter("changedate"));
foreach (FileObject d in liste) {
sqc.Parameters["path"].Value = d.Filepath;
sqc.Parameters["hash"].Value = d.Hash;
sqc.Parameters["size"].Value = d.Size;
sqc.Parameters["changedate"].Value = d.ChangeDate;
sqc.ExecuteNonQuery();
}
}
sqt.Commit();
}
}
示例2: CreateDB
public void CreateDB(string databaseFile)
{
if (!File.Exists(databaseFile))
{
// Create the database
SqliteConnection.CreateFile(databaseFile);
Console.Write("vt oluşturuldu");
}
else
Console.Write("vt mevcut");
try
{
// Connect to the database
using (SqliteConnection sqlCon = new SqliteConnection (String.Format ("Data Source = {0};", databaseFile)))
{
sqlCon.Open ();
// Create a table
using (SqliteCommand sqlCom = new SqliteCommand (sqlCon))
{
if(SubeSistemi=="Y")
sqlCom.CommandText = "CREATE TABLE IF NOT EXISTS EMIRLERY (ID INTEGER PRIMARY KEY, Title VARCHAR(20), Subject VARCHAR(20), PostDate VARCHAR(20), ImgUrl VARCHAR(20), DocAdress VARCHAR(20), Sube VARCHAR(11))";
else if(SubeSistemi=="Z") {
sqlCom.CommandText = "CREATE TABLE IF NOT EXISTS EMIRLERZ (ID INTEGER PRIMARY KEY, Title VARCHAR(20), Subject VARCHAR(20), PostDate VARCHAR(20), ImgUrl VARCHAR(20), DocAdress VARCHAR(20), Sube VARCHAR(11))";
}
else if (SubeSistemi=="X") {
sqlCom.CommandText = "CREATE TABLE IF NOT EXISTX EMIRLERX (ID INTEGER PRIMARY KEY, Title VARCHAR(20), Subject VARCHAR(20), PostDate VARCHAR(20), ImgUrl VARCHAR(20), DocAdress VARCHAR(20), Sube VARCHAR(11))";
}
sqlCom.ExecuteNonQuery ();
Console.WriteLine(sqlCom.ExecuteNonQuery());
}
//end using sqlCom
sqlCon.Close ();
}
//end using sqlCon
this.durumF.Text = "hazır!";
} catch (Exception ex)
{
this.durumF.Text = String.Format ("Sqlite error: {0}", ex.Message);
}//end try catch
}
示例3: CreateDB
public void CreateDB(string databaseFile)
{
try
{
// Check if database already exists
if (!File.Exists (databaseFile))
{
// Create the database
SqliteConnection.CreateFile (databaseFile);
// Connect to the database
using (SqliteConnection sqlCon = new SqliteConnection (String.Format ("Data Source = {0};", databaseFile)))
{
sqlCon.Open ();
// Create a table
using (SqliteCommand sqlCom = new SqliteCommand (sqlCon))
{
sqlCom.CommandText = "CREATE TABLE Personel (ID INTEGER PRIMARY KEY, UserName VARCHAR(20), Password VARCHAR(20))";
//veri Ekleme
//Update
// sqlCom.CommandText = "UPDATE Customers SET FirstName= 'Haluk' WHERE LastName = @lastName";
// sqlCom.Parameters.Add(new SqliteParameter("@lastName","Haluky"));
sqlCom.ExecuteNonQuery ();
Console.WriteLine(sqlCom.ExecuteNonQuery());
}
//end using sqlCom
sqlCon.Close ();
}
//end using sqlCon
this.durumGostericiT.Text = "Database hazır!";
} else
{
this.durumGostericiT.Text = "Database Mevcut!";
}//end if else
} catch (Exception ex)
{
this.durumGostericiT.Text = String.Format ("Sqlite error: {0}", ex.Message);
}//end try catch
}
示例4: CreateSQLiteDatabase
private void CreateSQLiteDatabase(string databaseFile)
{
try
{
// Check if database already exists
if (!File.Exists (databaseFile))
{
// Create the database
SqliteConnection.CreateFile (databaseFile);
// Connect to the database
using (SqliteConnection sqlCon = new SqliteConnection (String.Format ("Data Source = {0};", databaseFile)))
{
sqlCon.Open ();
// Create a table
using (SqliteCommand sqlCom = new SqliteCommand (sqlCon))
{
sqlCom.CommandText="CREATE TABLE Personel (ID INTEGER PRIMARY KEY, UserName VARCHAR(20), Password VARCHAR (20), Bolum VARCHAR(20), Gorev VARCHAR(20), Isim VARCHAR(20), Telefon VARCHAR(20), Email VARCHAR(20))";
sqlCom.ExecuteNonQuery ();
Console.WriteLine(sqlCom.ExecuteNonQuery());
}
//end using sqlCom
sqlCon.Close ();
}
//end using sqlCon
this.durumT.Text = "oluştu";
} else
{
this.durumT.Text = "Zaten var";
}//end if else
} catch (Exception ex)
{
this.durumT.Text = String.Format ("Sqlite error: {0}", ex.Message);
}//end try catch
}
示例5: CSQL_AddDevice
public bool CSQL_AddDevice(CDevice device)
{
string sql = "INSERT INTO devices VALUES ('" +
device.DeviceID + "', '" +
device.DeviceDescription + "', '" +
device.DeviceLocation + "', '" +
device.DeviceServer + "', '" +
device.DeviceServerSubDir + "');";
SqliteCommand dbhCmd;
int num_recs = 0;
if (CSQL_Connected ()) {
dbhCmd = new SqliteCommand (sql, dbh);
num_recs = dbhCmd.ExecuteNonQuery ();
if (num_recs > 0) {
CSQL_AddDeviceLogFileDescription (device, dbhCmd.Connection);
}
}
return false;
}
示例6: apply_Click
private void apply_Click(object sender, EventArgs e)
{
SqliteCommand command = new SqliteCommand(connection);
String date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
command.CommandText = "INSERT OR REPLACE INTO comments (guid, comment, date) VALUES (@guid, @comment, @date)";
command.Parameters.Add(new SqliteParameter("@guid", guid));
command.Parameters.Add(new SqliteParameter("@comment", input.Text));
command.Parameters.Add(new SqliteParameter("@date", date));
command.ExecuteNonQuery();
command.Dispose();
if (mode == "players")
{
Thread thread = new Thread(new ThreadStart(gui.thread_Player));
thread.IsBackground = true;
thread.Start();
}
else if (mode == "bans")
{
Thread thread = new Thread(new ThreadStart(gui.thread_Bans));
thread.IsBackground = true;
thread.Start();
}
else if (mode == "player database")
{
Thread thread = new Thread(new ThreadStart(gui.thread_Database));
thread.IsBackground = true;
thread.Start();
}
this.Close();
}
示例7: ExcuteTransaction
public bool ExcuteTransaction(string sql)
{
var cmds = sql.Split(';');
using (SqliteConnection conn = new SqliteConnection(this.SqlConfig.ConnectionString))
{
conn.Open();
SqliteCommand cmd = new SqliteCommand(conn);
SqliteTransaction tran = conn.BeginTransaction();
try
{
foreach (var cmdSql in cmds)
{
cmd.CommandText = cmdSql;
cmd.ExecuteNonQuery();
}
tran.Commit();
conn.Close();
return true;
}
catch (Exception e)
{
tran.Rollback();
conn.Close();
throw new Exception(e.Message + " sql:" + sql);
}
finally
{
conn.Close();
}
}
}
示例8: DateTimeConvert
public void DateTimeConvert ()
{
var dateTime = new DateTime (2016, 9, 15, 12, 1, 53);
var guid = Guid.NewGuid ();
using (var connection = new SqliteConnection ("Data Source=" + _databasePath)) {
connection.Open ();
var sqlCreate = "CREATE TABLE TestTable (ID uniqueidentifier PRIMARY KEY, Modified datetime)";
using (var cmd = new SqliteCommand (sqlCreate, connection)) {
cmd.ExecuteNonQuery ();
}
var sqlInsert = "INSERT INTO TestTable (ID, Modified) VALUES (@id, @mod)";
using (var cmd = new SqliteCommand (sqlInsert, connection)) {
cmd.Parameters.Add (new SqliteParameter ("@id", guid));
cmd.Parameters.Add (new SqliteParameter ("@mod", dateTime));
cmd.ExecuteNonQuery ();
}
}
using (var connection = new SqliteConnection ("Data Source=" + _databasePath)) {
connection.Open ();
var sqlSelect = "SELECT * from TestTable";
using (var cmd = new SqliteCommand (sqlSelect, connection))
using (var reader = cmd.ExecuteReader ()) {
while (reader.Read ()) {
Assert.AreEqual (guid, reader.GetGuid (0), "#1");
Assert.AreEqual (dateTime, reader.GetDateTime (1), "#2");
}
}
}
}
示例9: executeQuery
public static void executeQuery(string sql)
{
myConnection.Open();
SqliteCommand com = new SqliteCommand(sql, myConnection);
com.ExecuteNonQuery();
myConnection.Close();
}
示例10: CommitTransaction
public void CommitTransaction()
{
var lst = new List<string>();
using (var cmd = new SqliteCommand(String.Format("SELECT DISTINCT [TableName] FROM {0}", TranStatusTable), ActiveConnection))
{
using (SqliteDataReader r = cmd.ExecuteReader())
{
while (r.Read())
{
lst.Add(r.GetString(0));
}
}
}
SqliteTransaction tran = ActiveConnection.BeginTransaction();
try
{
foreach (String tableName in lst)
{
using (var cmd = new SqliteCommand(String.Format("DELETE FROM __{0}", tableName), tran.Connection, tran))
cmd.ExecuteNonQuery();
}
using (var cmd = new SqliteCommand(String.Format("DELETE FROM {0}", TranStatusTable), tran.Connection, tran))
cmd.ExecuteNonQuery();
tran.Commit();
}
catch
{
tran.Rollback();
throw;
}
}
示例11: Delete
public bool Delete(Guid presentationUID)
{
bool ret = false;
if (presentationUID == Guid.Empty)
return false;
using (SqliteConnection conn = GetConnection())
{
using (SqliteCommand sqlCmd = new SqliteCommand(@"
BEGIN; " +
"DELETE FROM presentations " +
"WHERE [email protected];" +
"COMMIT;", conn))
{
sqlCmd.Parameters.AddWithValue("@PresentationUID", presentationUID.ToString());
conn.Open();
try
{
sqlCmd.ExecuteNonQuery();
ret = true;
}
catch (SqliteException ex)
{
Logging.Log(this, Logging.LoggingTypeError, "SQL cmd: " + sqlCmd, ex);
}
conn.Close();
}
}
return ret;
}
示例12: addWorker
public override bool addWorker(string fname, string lname, string village, string hnr, int plz, string email, string mobile, string tel, string street)
{
try
{
sqlite_cmd = sqlite_conn.CreateCommand ();
sqlite_cmd.CommandText = "INSERT INTO tbl_worker (fname, lname, hnr, PLZ, village, email, mobile, telephone, street) VALUES ('"+fname+"', '"+lname+"','"+hnr+"','"+plz+"','"+village+"','"+email+"','"+mobile+"','"+tel+"','"+street+"')";
sqlite_conn.Open();
sqlite_cmd.ExecuteNonQuery();
sqlite_conn.Close();
int WorkerID = this.readWorkerID(fname,lname,village,hnr,email);
if(WorkerID != 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
sqlite_conn.Close ();
return false;
}
}
示例13: ExecuteNonQuery
protected int ExecuteNonQuery(SqliteCommand cmd)
{
try
{
lock (m_Connection)
{
var newConnection =
(SqliteConnection)((ICloneable)m_Connection).Clone();
if (newConnection.State != ConnectionState.Open)
newConnection.Open();
cmd.Connection = newConnection;
return cmd.ExecuteNonQuery();
}
}
catch (Mono.Data.Sqlite.SqliteException)
{
//m_log.Warn("[SQLiteDataManager]: Exception processing command: " + cmd.CommandText + ", Exception: " + ex);
//throw ex;
}
catch (Exception ex)
{
m_log.Warn("[SQLiteDataManager]: Exception processing command: " + cmd.CommandText + ", Exception: " + ex);
throw ex;
}
return 0;
}
示例14: MakeSureTableExists
private void MakeSureTableExists()
{
using (SqliteCommand sqc = new SqliteCommand(connection)) {
sqc.CommandText = "CREATE TABLE IF NOT EXISTS `Files` (`id` INTEGER NOT NULL PRIMARY KEY, `path` TEXT NOT NULL, `changedate` INTEGER NOT NULL, `size` INTEGER NOT NULL, `hash` TEXT NOT NULL)";
sqc.ExecuteNonQuery();
}
}
示例15: NonQuery
public void NonQuery( string cmdstr )
{
using (var cmd = new SqliteCommand( con )) {
cmd.CommandText = cmdstr;
cmd.ExecuteNonQuery();
}
}