本文整理汇总了C#中SqliteCommand.ExecuteReader方法的典型用法代码示例。如果您正苦于以下问题:C# SqliteCommand.ExecuteReader方法的具体用法?C# SqliteCommand.ExecuteReader怎么用?C# SqliteCommand.ExecuteReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqliteCommand
的用法示例。
在下文中一共展示了SqliteCommand.ExecuteReader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btn_Save_Click
private void btn_Save_Click(object sender, EventArgs e)
{
try
{
using (SqliteConnection sqlCnnctn = new SqliteConnection())
{
sqlCnnctn.ConnectionString = _ConnectionString;
sqlCnnctn.Open();
using (SqliteCommand sqlCmmnd = new SqliteCommand())
{
sqlCmmnd.Connection = sqlCnnctn;
sqlCmmnd.CommandText =
"UPDATE t_news_category " +
" SET n_dscr = @n_dscr " +
" WHERE news_category_id = " + _CatID.ToString();
sqlCmmnd.Parameters.Add("@n_dscr", DbType.String).Value = tbx_NDscr.Text.Trim();
using (SqliteDataReader sqlDReader = sqlCmmnd.ExecuteReader())
{
if (sqlDReader.HasRows && sqlDReader.Read())
{
lbl_NCategory.Text = sqlDReader["news_category"].ToString();
lbl_NSource.Text = sqlDReader["n_source"].ToString();
tbx_NDscr.Text = sqlDReader["n_dscr"].ToString();
}
sqlDReader.Close();
}
}
sqlCnnctn.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
Close();
}
示例2: HasNewCategory
/// <summary>
/// Проверява за нови категории
/// </summary>
private bool HasNewCategory(SqliteCommand aSQLCmmnd)
{
bool bRes = false;
//
aSQLCmmnd.CommandText =
"SELECT news_category " +
" FROM tmp_news " +
" WHERE ( ifnull(news_category_id, 0) = 0 ); ";
using (SqliteDataReader dr = aSQLCmmnd.ExecuteReader())
{
bRes = dr.HasRows;
dr.Close();
}
return bRes;
}
示例3: TmpNewsTransfer
/// <summary>
/// Зарежда новите новини
/// </summary>
public void TmpNewsTransfer(SqliteCommand aCmmndNews, SqliteCommand aCmmndEncl)
{
DataTable dtNews = new DataTable();
aCmmndNews.CommandText =
"SELECT tmp_news.news_id FROM tmp_news ";
using (SqliteDataAdapter sqlDAdapter = new SqliteDataAdapter(aCmmndNews))
{
dtNews.Clear();
sqlDAdapter.Fill(dtNews);
}
// Ако няма новини - КРАЙ
if (dtNews.Rows.Count == 0)
{ return; }
Int32 iNewsID = 0;
// ID на последната новина
aCmmndNews.CommandText =
"SELECT ifnull(max(news.news_id),0) AS news_id " +
" FROM news ";
using (SqliteDataReader dr = aCmmndNews.ExecuteReader())
{
if (dr.HasRows && dr.Read())
{
if (dr["news_id"].ToString().Equals(""))
{
iNewsID = 1;
}
else
{
iNewsID = Convert.ToInt32(dr["news_id"]) + 1;
}
}
else
{
throw new Exception("Exception: TmpNewsTransfer");
}
dr.Close();
}
// Новини
aCmmndNews.CommandText = "INSERT INTO news ( news_id, news_site_id, news_guid, news_title, news_link, news_description, news_body, news_comments, news_pubdate, news_category_id ) "
+ " SELECT @news_id "
+ " , tmp_news.news_site_id "
+ " , tmp_news.news_guid "
+ " , tmp_news.news_title "
+ " , tmp_news.news_link "
+ " , tmp_news.news_description "
+ " , tmp_news.news_body "
+ " , tmp_news.news_comments "
+ " , tmp_news.news_pubdate "
+ " , tmp_news.news_category_id "
+ " FROM tmp_news "
+ " WHERE ( tmp_news.news_id = @tmp_news_id ); ";
aCmmndNews.Parameters.Clear();
aCmmndNews.Parameters.Add("@news_id", DbType.Int32);
aCmmndNews.Parameters.Add("@tmp_news_id", DbType.Int32);
// Новини - Картинки
aCmmndEncl.CommandText = "INSERT INTO enclosure ( news_id, encl_link, encl_id ) "
+ " SELECT @news_id "
+ " , tmp_enclosure.encl_link "
+ " , tmp_enclosure.encl_id "
+ " FROM tmp_enclosure "
+ " WHERE ( tmp_enclosure.news_id = @tmp_news_id ); ";
aCmmndEncl.Parameters.Clear();
aCmmndEncl.Parameters.Add("@news_id", DbType.Int32);
aCmmndEncl.Parameters.Add("@tmp_news_id", DbType.Int32);
foreach (DataRow dr in dtNews.Rows)
{
//
aCmmndNews.Parameters["@news_id"].Value = iNewsID;
aCmmndNews.Parameters["@tmp_news_id"].Value = dr["news_id"];
aCmmndNews.ExecuteNonQuery();
aCmmndEncl.Parameters["@news_id"].Value = iNewsID;
aCmmndEncl.Parameters["@tmp_news_id"].Value = dr["news_id"];
aCmmndEncl.ExecuteNonQuery();
iNewsID++;
}
}
示例4: TmpNewsRepair
/// <summary>
/// Обработва новните във временните таблици
/// </summary>
public void TmpNewsRepair(SqliteCommand aCmmndNews)
{
// Изтрива старите новини
aCmmndNews.CommandText =
"DELETE FROM tmp_news " +
" WHERE news_pubdate < @FromDate ";
aCmmndNews.Parameters.Clear();
aCmmndNews.Parameters.Add("@FromDate", DbType.Date).Value = DateTime.Now.AddMonths(-1);
aCmmndNews.ExecuteNonQuery();
// Изтрива новини с бъдеща дата
aCmmndNews.CommandText =
"DELETE FROM tmp_news " +
" WHERE news_pubdate > @FromDate ";
aCmmndNews.Parameters.Clear();
aCmmndNews.Parameters.Add("@FromDate", DbType.Date).Value = DateTime.Now.AddDays(1);
aCmmndNews.ExecuteNonQuery();
//
aCmmndNews.Parameters.Clear();
// Изтрива дублиращите се новини
aCmmndNews.CommandText =
"DELETE FROM tmp_news " +
" WHERE tmp_news.news_id in (SELECT tmp_news.news_id " +
" FROM news " +
" INNER JOIN tmp_news " +
" ON (news.news_guid = tmp_news.news_guid) " +
" AND (news.news_site_id = tmp_news.news_site_id)); ";
aCmmndNews.ExecuteNonQuery();
// Изтрива новините без картинки
aCmmndNews.CommandText =
"DELETE FROM tmp_news " +
" WHERE news_id NOT IN ( SELECT news_id FROM tmp_enclosure ) ";
OnLog(LogMessageType.Event, "- Изтрити новините без картинки: " + aCmmndNews.ExecuteNonQuery().ToString());
// Новини за добавяне
using (DataTable dtNews = new DataTable())
{
aCmmndNews.CommandText =
"SELECT tmp_news.news_id " +
" FROM tmp_news ";
using (SqliteDataAdapter sqlDAdapter = new SqliteDataAdapter(aCmmndNews))
{
dtNews.Clear();
sqlDAdapter.Fill(dtNews);
}
// Ако няма новини - КРАЙ
if (dtNews.Rows.Count == 0)
{ return; }
}
// Определя типа на Enclosure
aCmmndNews.CommandText =
"UPDATE tmp_enclosure " +
" SET encl_id = (SELECT encl.encl_id " +
" FROM t_enclosure encl " +
" WHERE tmp_enclosure.encl_type = encl.encl_type); ";
aCmmndNews.ExecuteNonQuery();
// Проверка за непознат тип на Enclosure
aCmmndNews.CommandText = "SELECT tmp_enclosure.encl_type "
+ " FROM tmp_enclosure "
+ " WHERE ( tmp_enclosure.encl_id = 0 ); ";
using (SqliteDataReader dr = aCmmndNews.ExecuteReader())
{
if (dr.HasRows)
{
string sMsg = "Неразпознат тип на 'Enclosure' !";
if (dr.Read())
{
sMsg += dr["encl_type"].ToString();
}
throw new Exception(sMsg);
}
dr.Close();
}
// Категории на новините
/* прецаква кодовата таблица
// Стандартизира news_category
aCmmndNews.CommandText =
"UPDATE tmp_news " +
" SET news_category = lower(trim(news_category)); ";
aCmmndNews.ExecuteNonQuery();
*/
// Определя категориите на новините
SetNewsCategory(aCmmndNews);
while (HasNewCategory(aCmmndNews))
{
AddNewCategory(aCmmndNews);
SetNewsCategory(aCmmndNews);
}
// Връзка м/у таблициците с категории
aCmmndNews.CommandText =
"INSERT INTO x_news_nweb " +
" ( news_category_id, nweb_category_id ) " +
" SELECT nct.news_category_id " +
//.........这里部分代码省略.........
示例5: ExecuteReader
protected IDataReader ExecuteReader(SqliteCommand cmd, SqliteConnection connection)
{
cmd.Connection = connection;
return cmd.ExecuteReader();
}
示例6: ExecuteReader
protected IDataReader ExecuteReader(SqliteCommand cmd, SqliteConnection connection)
{
lock (connection)
{
//SqliteConnection newConnection =
// (SqliteConnection)((ICloneable)connection).Clone();
//newConnection.Open();
//cmd.Connection = newConnection;
cmd.Connection = connection;
//Console.WriteLine("XXX " + cmd.CommandText);
return cmd.ExecuteReader();
}
}
示例7: ExistsAsset
// /// <summary>
// /// Some... logging functionnality
// /// </summary>
// /// <param name="asset"></param>
// private static void LogAssetLoad(AssetBase asset)
// {
// string temporary = asset.Temporary ? "Temporary" : "Stored";
// string local = asset.Local ? "Local" : "Remote";
//
// int assetLength = (asset.Data != null) ? asset.Data.Length : 0;
//
// m_log.Debug("[ASSET DB]: " +
// string.Format("Loaded {5} {4} Asset: [{0}][{3}] \"{1}\":{2} ({6} bytes)",
// asset.FullID, asset.Name, asset.Description, asset.Type,
// temporary, local, assetLength));
// }
/// <summary>
/// Check if an asset exist in database
/// </summary>
/// <param name="uuid">The asset UUID</param>
/// <returns>True if exist, or false.</returns>
override public bool ExistsAsset(UUID uuid)
{
lock (this) {
using (SqliteCommand cmd = new SqliteCommand(SelectAssetSQL, m_conn))
{
cmd.Parameters.Add(new SqliteParameter(":UUID", uuid.ToString()));
using (IDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
reader.Close();
return true;
}
else
{
reader.Close();
return false;
}
}
}
}
}
示例8: LoadTerrain
// Returns 'null' if region not found
public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
{
TerrainData terrData = null;
lock (ds)
{
String sql = "select RegionUUID, Revision, Heightfield from terrain" +
" where RegionUUID=:RegionUUID order by Revision desc";
using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
{
cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
using (IDataReader row = cmd.ExecuteReader())
{
int rev = 0;
if (row.Read())
{
rev = Convert.ToInt32(row["Revision"]);
byte[] blob = (byte[])row["Heightfield"];
terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
}
else
{
m_log.Warn("[SQLITE REGION DB]: No terrain found for region");
return null;
}
m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString());
}
}
}
return terrData;
}
示例9: SelectData
public void SelectData(string databaseFile)
{
try
{
if (!File.Exists (databaseFile))
{
this.durumGostericiT.Text = "Database file does not exis using (SqliteConnection sqlCon = new SqliteConnection (String.Format (\"Data Source = {0}\", databaseFile))) \nt. Tap the appropriate button to create it.";
return;
}
//end if
// Connect to database
using (SqliteConnection sqlCon = new SqliteConnection (String.Format ("Data Source = {0}", databaseFile)))
{
sqlCon.SetPassword("haluk");
sqlCon.Open ();
using (SqliteCommand sqlCom = new SqliteCommand (sqlCon))
{
sqlCom.CommandText = "SELECT * FROM Personel WHERE Password = @lastName and UserName = @username";
sqlCom.Parameters.Add (new SqliteParameter ("@lastName", passwordF.Text));
sqlCom.Parameters.Add (new SqliteParameter ("@username", usernameF.Text));
// Execute the SELECT statement and retrieve the data
using (SqliteDataReader dbReader = sqlCom.ExecuteReader ())
{
if (dbReader.HasRows)
{
// Advance through each row
while (dbReader.Read ())
{
durumGostericiT.Text="eşlenme sağlandı";
this.usernameF.Text += String.Format ("ID: {0}\n", Convert.ToString (dbReader["UserName"]));
this.passwordF.Text += String.Format (" : {0}\n", Convert.ToString (dbReader["Password"]));
this.PerformSegue("GondericiC",this);
}
//end while
}
//end if
}//end using dbReader
}
//end using sqlCom
sqlCon.Close ();
}
//end using sqlCon
// this.durumGostericiT.Text += "Customer data retrieved.\n";
} catch (Exception ex)
{
this.durumGostericiT.Text = String.Format ("{0}", ex.Message);
}
//end try catch
}
示例10: OnCreate
//.........这里部分代码省略.........
//We can use WriteItemChanges() - writes any in-memory item changes to the table
//encTable.WriteItemChanges();
//OR WriteChangesAndFlush() writes any in-memory items to the table, and then drops any in-memory items and/or in-memory index of the table
//Normally, only items that are out-of-sync with the table are written, forceWriteAll causes all items (whether they have changed or not)
// to be written
encTable.WriteChangesAndFlush(forceWriteAll: true);
//How many items in memory now?
Console.WriteLine("After WriteChangesAndFlush() there are now {0} items in memory.", encTable.TempItems.Count());
//How many records in the table?
numRecords = SampleDataItem.GetNumRecords(dbConn, encTable.TableName);
Console.WriteLine("After WriteChangesAndFlush() there are now {0} records in the table.", numRecords.ToString());
}
//Reading and searching for items/records
using (var encTable = new EncryptedTable<SampleDataItem>(this.AppCryptEngine, dbConn)) {
//Doing a GetItems() with an empty TableSearch (like the line below) will get all items
List<SampleDataItem> allItems = encTable.GetItems(new TableSearch());
foreach (var item in allItems) {
Console.WriteLine("In table: ID#{0} {1} {2}", item.Id, item.FirstName, item.LastName);
}
//Let's just get one item - exceptionOnMissingItem: true will throw an exception if the item wasn't found
// in the table; with exceptionOnMissingItem: false, we will just get a null
SampleDataItem singleItem = encTable.GetItem(allItems.First().Id, exceptionOnMissingItem: true);
Console.WriteLine("Found via ID: ID#{0} {1} {2}", singleItem.Id, singleItem.FirstName, singleItem.LastName);
//Because we did a full table GetItems() above, we should have a nice, searchable index of all of the
// items in the table. But let's check it and re-build if necessary
encTable.CheckFullTableIndex(rebuildIfExpired: true);
//Otherwise, we could just force a rebuild of the searchable index
// encTable.BuildFullTableIndex();
//So, the easy way to find matching items, based on the full table index is to pass in a TableSearch
List<SampleDataItem> matchingItems = encTable.GetItems(new TableSearch {
SearchType = TableSearchType.MatchAll, //Items must match all search criteria
MatchItems = {
new TableSearchItem("LastName", "Johnson", SearchItemMatchType.IsEqualTo),
new TableSearchItem("FirstName", "Ned", SearchItemMatchType.DoesNotContain)
}
});
foreach (var item in matchingItems) {
Console.WriteLine("Found via search: ID#{0} {1} {2}", item.Id, item.FirstName, item.LastName);
}
//Let's see what is in this "full table index" anyway
foreach (var item in encTable.FullTableIndex.Index) {
Console.WriteLine("Indexed item ID: " + item.Key.ToString());
foreach (var value in item.Value) {
Console.WriteLine(" - Searchable value: {0} = {1}", value.Key ?? "", value.Value ?? "");
}
}
//Let's remove/delete a record from the table (with immediate removal)
Console.WriteLine("Deleting record: ID#{0} {1} {2}", singleItem.Id, singleItem.FirstName, singleItem.LastName);
encTable.RemoveItem(singleItem.Id, immediateWriteToTable: true);
//Let's see what is actually in the table
Console.WriteLine("Records in the table " + encTable.TableName + " - ");
sql = "select * from " + encTable.TableName;
using (var cmd = new SqliteCommand(sql, dbConn)) {
using (SqliteDataReader reader = cmd.ExecuteReader()) {
while (reader.Read()) {
var record = new StringBuilder();
foreach (Portable.Data.Sqlite.TableColumn column in encTable.TableColumns.Values.OrderBy(tc => tc.ColumnOrder)) {
if (column.ColumnName == "Id") { record.Append(column.ColumnName + ": " + reader[column.ColumnName].ToString()); }
else {
record.Append(" - " + column.ColumnName + ": " + (reader[column.ColumnName].ToString() ?? ""));
}
}
Console.WriteLine(record.ToString());
}
}
}
}
}
#endregion
Console.WriteLine("Done.");
//Pop up a message saying we are done
var dialog = new AlertDialog.Builder(this);
dialog.SetMessage("If you can see this message, then the sample Portable.Data.Sqlite code ran correctly. " +
"Take a look at the code in the 'MainActivity.cs' file, and compare it to what you are seeing in the IDE Output window. " +
"And have a nice day...");
dialog.SetCancelable(false);
dialog.SetPositiveButton("OK", delegate { });
dialog.Create().Show();
#endregion
}
示例11: SetLastSendNews
private void SetLastSendNews(SqliteConnection aSqlCnnctn)
{
using (SqliteCommand sqlCmmnd = new SqliteCommand())
{
sqlCmmnd.Connection = aSqlCnnctn;
Int64 iLastSendNews = 0;
sqlCmmnd.CommandText =
"SELECT MAX(news.news_id) AS max_news_id FROM news ";
using (SqliteDataReader sqlDReader = sqlCmmnd.ExecuteReader())
{
if (sqlDReader.HasRows && sqlDReader.Read())
{
iLastSendNews = Convert.ToInt64(sqlDReader["max_news_id"]);
}
sqlDReader.Close();
}
//
sqlCmmnd.CommandText = "UPDATE news_setting "
+ " SET prm_value_int = " + iLastSendNews.ToString()
+ " WHERE prm_name = 'last_send_news' ";
sqlCmmnd.ExecuteNonQuery();
}
}
示例12: GetLastSendNews
private Int64 GetLastSendNews(SqliteConnection aSqlCnnctn)
{
Int64 iLastSendNews = 0;
using (SqliteCommand sqlCmmnd = new SqliteCommand())
{
sqlCmmnd.Connection = aSqlCnnctn;
//
sqlCmmnd.CommandText = "SELECT news_setting.prm_value_int "
+ " FROM news_setting "
+ " WHERE news_setting.prm_name = 'last_send_news' ";
using (SqliteDataReader sqlDReader = sqlCmmnd.ExecuteReader())
{
if (sqlDReader.HasRows && sqlDReader.Read())
{
iLastSendNews = Convert.ToInt64(sqlDReader["prm_value_int"]);
}
sqlDReader.Close();
}
}
return iLastSendNews;
}
示例13: AssetsExist
// /// <summary>
// /// Some... logging functionnality
// /// </summary>
// /// <param name="asset"></param>
// private static void LogAssetLoad(AssetBase asset)
// {
// string temporary = asset.Temporary ? "Temporary" : "Stored";
// string local = asset.Local ? "Local" : "Remote";
//
// int assetLength = (asset.Data != null) ? asset.Data.Length : 0;
//
// m_log.Debug("[ASSET DB]: " +
// string.Format("Loaded {5} {4} Asset: [{0}][{3}] \"{1}\":{2} ({6} bytes)",
// asset.FullID, asset.Name, asset.Description, asset.Type,
// temporary, local, assetLength));
// }
/// <summary>
/// Check if the assets exist in the database.
/// </summary>
/// <param name="uuids">The assets' IDs</param>
/// <returns>For each asset: true if it exists, false otherwise</returns>
public override bool[] AssetsExist(UUID[] uuids)
{
if (uuids.Length == 0)
return new bool[0];
HashSet<UUID> exist = new HashSet<UUID>();
string ids = "'" + string.Join("','", uuids) + "'";
string sql = string.Format("select UUID from assets where UUID in ({0})", ids);
using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
{
using (IDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
UUID id = new UUID((string)reader["UUID"]);
exist.Add(id);
}
}
}
bool[] results = new bool[uuids.Length];
for (int i = 0; i < uuids.Length; i++)
results[i] = exist.Contains(uuids[i]);
return results;
}
示例14: SqList
public void SqList(string databaseFile,string opinion)
{
try
{
if (!File.Exists (databaseFile))
{
return;
}
//end if
// Connect to database
using (SqliteConnection sqlCon = new SqliteConnection (String.Format ("Data Source = {0}", databaseFile)))
{
sqlCon.SetPassword("haluk");
sqlCon.Open ();
using (SqliteCommand sqlCom = new SqliteCommand (sqlCon))
{
sqlCom.CommandText="SELECT * FROM Personel";
// if(opinion=="Z")
// sqlCom.CommandText = "SELECT * FROM ZSUBE";
//
// else if(opinion=="Y")
// sqlCom.CommandText = "SELECT * FROM YSUBE";
//
// Execute the SELECT statement and retrieve the data
using (SqliteDataReader dbReader = sqlCom.ExecuteReader ())
{
if (dbReader.HasRows)
{
int i;
// Advance through each row
tasks = new List<TaskX> ();
while (dbReader.Read ())
{
TaskX dtask= new TaskX() {Id = Convert.ToInt16( dbReader["ID"]),
Name = String.Format (Convert.ToString (dbReader["UserName"])),
Notes=String.Format ( Convert.ToString (dbReader["Password"])),
Done=false};
tasks.Add(dtask);
};
}
};
TableView.Source = new RootTableSource(tasks.ToArray ());
}
sqlCon.Close ();
}
} catch (Exception ex)
{ }
}
示例15: DoLoad
private EstateSettings DoLoad(SqliteCommand cmd, UUID regionID, bool create)
{
EstateSettings es = new EstateSettings();
es.OnSave += StoreEstateSettings;
IDataReader r = null;
try
{
r = cmd.ExecuteReader();
}
catch (SqliteException)
{
m_log.Error("[SQLITE]: There was an issue loading the estate settings. This can happen the first time running OpenSimulator with CSharpSqlite the first time. OpenSimulator will probably crash, restart it and it should be good to go.");
}
if (r != null && r.Read())
{
foreach (string name in FieldList)
{
if (m_FieldMap[name].GetValue(es) is bool)
{
int v = Convert.ToInt32(r[name]);
if (v != 0)
m_FieldMap[name].SetValue(es, true);
else
m_FieldMap[name].SetValue(es, false);
}
else if (m_FieldMap[name].GetValue(es) is UUID)
{
UUID uuid = UUID.Zero;
UUID.TryParse(r[name].ToString(), out uuid);
m_FieldMap[name].SetValue(es, uuid);
}
else
{
m_FieldMap[name].SetValue(es, Convert.ChangeType(r[name], m_FieldMap[name].FieldType));
}
}
r.Close();
}
else if (create)
{
DoCreate(es);
LinkRegion(regionID, (int)es.EstateID);
}
LoadBanList(es);
es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
return es;
}