SQLiteCommand 的變數定義自行參考 SQLite.Net 的 Help
關於其他的SQL 語法,可以參考
在SQL 相關刪除的語法有3個
delete 刪除特定欄位在某個table
例
DELETE FROM employee WHERE id = 100;
truncate 刪除所有欄位在某個table
例
TRUNCATE TABLE employee;
但 SQLite 沒有 truncate 但可以用
DELETE FROM employee 的語法達成同樣效果
drop 刪除整個table
例
DROP TABLE employee;
以下例子,顯示相關SQLite語法
例一 刪除 table tbl 中 id =3的欄位
public void DeleteExampleTable(SQLiteCommand cmd)
{
try
{
/// Set Delete command
cmd.CommandText = "DELETE FROM [tbl] where id=3";
/// Execute the command, iF have not exist show error message
cmd.ExecuteNonQuery();
MessageBox.Show("delete OK");
}
catch
{
MessageBox.Show("delete Error");
}
}
例二 刪除 table tbl 所有的欄位達成 truncate 的效果
public void DeleteExampleTable(SQLiteCommand cmd)
{
try
{
/// Set Delete command
cmd.CommandText = "DELETE FROM [tbl]";
/// Execute the command, iF have not exist show error message
cmd.ExecuteNonQuery();
MessageBox.Show("delete OK");
}
catch
{
MessageBox.Show("delete Error");
}
}
例三 刪除 table tbl (drop)
public void DROPExampleTable(SQLiteCommand cmd)
{
try
{
/// Set drop table command
cmd.CommandText = "DROP TABLE [table]";
/// Execute the command, iF have not exist show error message
cmd.ExecuteNonQuery();
MessageBox.Show("Drop OK");
}
catch
{
MessageBox.Show("Drop Error");
}
}
沒有留言:
張貼留言