本文操作是测试数据库的其中一张表,其中包括清空sqlite数据库MyGroup表中的数据,清空sqlite数据库sqlite_sequence表中的自增变量,sqlite数据库MyGroup直接插入数据 40000000,sqlite数据库MyGroup 参数插入数据 80000000

using System;
using System.Data;
using System.Data.SQLite;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks; namespace SupremeConsole
{
class Program
{
static void Main(string[] args)
{
#region 测试sqlite数据库
//GetSqliteData();
GetSqliteData2();
Thread.Sleep(TimeSpan.FromSeconds());
GetSqliteData3();
Thread.Sleep(TimeSpan.FromSeconds());
GetSqliteData4();
Thread.Sleep(TimeSpan.FromSeconds());
GetSqliteData5();
#endregion
Console.ReadLine();
}
/// <summary>
/// 使用sqlite获取数据
/// </summary>
public static void GetSqliteData()
{
SQLiteConnection sqLiteConn = new SQLiteConnection("Data source=" + Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data"), "mysqlite.db"));
sqLiteConn.Open();
SQLiteCommand sqLiteCmd = new SQLiteCommand
{
Connection = sqLiteConn,
CommandType = CommandType.Text,
//CommandText = "select * from mydb"//DELETE FROM MyGroup;UPDATE sqlite_sequence SET seq = 0 WHERE name = 'MyGroup';
}; SQLiteDataAdapter sqLiteDataAdapter = new SQLiteDataAdapter
{
SelectCommand = sqLiteCmd
};
DataSet dataSet = new DataSet();
sqLiteDataAdapter.Fill(dataSet);
sqLiteConn.Close();
foreach (DataRow item in dataSet.Tables[].Rows)
{
Console.WriteLine($"db_name:{item.ItemArray[2].ToString()},hash_value:{item.ItemArray[3].ToString()}");
}
//string ss =$"编号:{dataSet.Tables[0].Rows[0].ItemArray[2].ToString()},姓名:{dataSet.Tables[0].Rows[0].ItemArray[3].ToString()}";
//return ss;
} /// <summary>
/// 清空sqlite数据库MyGroup表中的数据
/// </summary>
public static void GetSqliteData2()
{
using (SQLiteConnection sqLiteConn = new SQLiteConnection("Data source=" + Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data"), "mysqlite.db")))
{
sqLiteConn.Open();
SQLiteTransaction sqLiteTransaction = sqLiteConn.BeginTransaction();
SQLiteCommand sqLiteCmd = new SQLiteCommand
{
Connection = sqLiteConn,
CommandType = CommandType.Text,
Transaction = sqLiteTransaction,
CommandText = "DELETE FROM MyGroup"//DELETE FROM MyGroup;UPDATE sqlite_sequence SET seq = 0 WHERE name = 'MyGroup';
};
try
{
int s = sqLiteCmd.ExecuteNonQuery();
Console.WriteLine($"清空sqlite数据库MyGroup表中的数据 ok");
sqLiteTransaction.Commit(); }
catch (Exception)
{
Console.WriteLine($"清空sqlite数据库MyGroup表中的数据 error");
sqLiteTransaction.Rollback();
//throw;
}
finally
{
sqLiteConn.Close();
}
}
} /// <summary>
/// 清空sqlite数据库sqlite_sequence表中的自增变量
/// </summary>
public static void GetSqliteData3()
{
SQLiteConnection sqLiteConn = new SQLiteConnection("Data source=" + Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data"), "mysqlite.db"));
sqLiteConn.Open();
SQLiteTransaction sqLiteTransaction = sqLiteConn.BeginTransaction();
try
{
SQLiteCommand sqLiteCmd = new SQLiteCommand
{
Connection = sqLiteConn,
CommandType = CommandType.Text,
//CommandText = "select * from mydb"
Transaction = sqLiteTransaction,
CommandText = "UPDATE sqlite_sequence SET seq = 0 WHERE name = 'MyGroup'"//DELETE FROM MyGroup;UPDATE sqlite_sequence SET seq = 0 WHERE name = 'MyGroup';
};
sqLiteCmd.ExecuteNonQuery();
sqLiteTransaction.Commit();
Console.WriteLine($"清空sqlite数据库sqlite_sequence表中的自增变量 ok");
}
catch (Exception)
{
sqLiteTransaction.Rollback();
Console.WriteLine($"清空sqlite数据库sqlite_sequence表中的自增变量 error");
}
finally
{
sqLiteConn.Close();
}
} /// <summary>
/// sqlite数据库MyGroup直接插入数据 40000000
/// </summary>
public static void GetSqliteData4()
{
SQLiteConnection sqLiteConn = new SQLiteConnection("Data source=" + Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data"), "mysqlite.db"));
sqLiteConn.Open();
SQLiteTransaction sqLiteTransaction = sqLiteConn.BeginTransaction();
try
{
SQLiteCommand sqLiteCmd = new SQLiteCommand
{
Connection = sqLiteConn,
CommandType = CommandType.Text,
//CommandText = "select * from mydb"
Transaction = sqLiteTransaction,
CommandText = "INSERT INTO MyGroup (group_name, start_id, end_id) VALUES ('group01', 0, 40000000)"//DELETE FROM MyGroup;UPDATE sqlite_sequence SET seq = 0 WHERE name = 'MyGroup';
};
sqLiteCmd.ExecuteNonQuery();
sqLiteTransaction.Commit();
Console.WriteLine($"sqlite数据库MyGroup插入数据 40000000 ok");
}
catch (Exception)
{
sqLiteTransaction.Rollback();
Console.WriteLine($"sqlite数据库MyGroup插入数据 40000000 error");
}
finally
{
sqLiteConn.Close();
}
} /// <summary>
/// sqlite数据库MyGroup参数插入数据 80000000
/// </summary>
public static void GetSqliteData5()
{
SQLiteConnection sqLiteConn = new SQLiteConnection("Data source=" + Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data"), "mysqlite.db"));
sqLiteConn.Open();
SQLiteTransaction sqLiteTransaction = sqLiteConn.BeginTransaction();
try
{ //INSERT INTO MyGroup (group_name, start_id, end_id) VALUES ("group02", 40000000, 80000000);
SQLiteCommand sqLiteCmd = new SQLiteCommand
{
Connection = sqLiteConn,
CommandType = CommandType.Text,
Transaction = sqLiteTransaction,
CommandText = "INSERT INTO MyGroup (group_name, start_id, end_id) VALUES (@group_name, @start_id, @end_id)"//DELETE FROM MyGroup;UPDATE sqlite_sequence SET seq = 0 WHERE name = 'MyGroup';
};
SQLiteParameter sQLiteParameter = new SQLiteParameter("@group_name", DbType.String);
sQLiteParameter.Value = "group02";
sqLiteCmd.Parameters.Add(sQLiteParameter);
SQLiteParameter sQLiteParameter1 = new SQLiteParameter("@start_id", DbType.Int32);
sQLiteParameter1.Value = ;
sqLiteCmd.Parameters.Add(sQLiteParameter1);
SQLiteParameter sQLiteParameter2 = new SQLiteParameter("@end_id", DbType.Int32);
sQLiteParameter2.Value = ;
sqLiteCmd.Parameters.Add(sQLiteParameter2);
sqLiteCmd.ExecuteNonQuery();
sqLiteTransaction.Commit();
Console.WriteLine($"sqlite数据库MyGroup插入数据 80000000 ok");
}
catch (Exception)
{
sqLiteTransaction.Rollback();
Console.WriteLine($"sqlite数据库MyGroup插入数据 80000000 error");
}
finally
{
sqLiteConn.Close();
}
}
}
}

以上仅仅是根据本作者的sqlite数据库来写的操作,具体情况需要具体修改。

附加数据库:mysqlite.db

sqlite数据库使用具体案例以及mysqlite.db数据库的更多相关文章

  1. jmeter通过org.sqlite.JDBC驱动连接db数据库

    最近遇到个项目,默认业务库为内置db数据库,在性能脚本编辑过程中要通过正则表达式提取器(关联)获取对应的id号,通过该id号到db数据库中查找对应的数据源name字段内容,为下一个post请求做par ...

  2. APICloud框架—db数据库模块

    db数据库模块 db 模块封装了手机常用数据库 sqlite 的增删改查语句,可实现数据的本地存储,极大的简化了数据持久化问题,本模块已支持同步接口. 官方文档地址 打开/新建一个数据库 functi ...

  3. AndroidStudio 中查看获取MD5和SHA1值以及如何查看手机应用信息以及读取*.db数据库里面数据

    查看获取MD5和SHA1值具体操作方式链接 查看获取MD5和SHA1值实际操作命令CMD语句: C:\Users\Administrator>cd .android C:\Users\Admin ...

  4. atitit.数据验证--db数据库数据验证约束

    atitit.数据验证--db数据库数据验证约束 1. 为了加强账户数据金额的安全性,需要增加验证字段..1 2. 创建帐户1 3. 更改账户2 4. ---code3 5. --fini4 1. 为 ...

  5. BDB (Berkeley DB)数据库简单介绍(转载)

    近期要使用DBD,于是搜了下相关的资料,先贴个科普性的吧: 转自http://www.javaeye.com/topic/202990 DB综述DB最初开发的目的是以新的HASH訪问算法来取代旧的hs ...

  6. 5. 文件上传下载 与 db数据库

    文件上传 formidable multer npm i formidable multer 如何使用见: https://www.npmjs.com/ util.inspect 自己查 文件上传:表 ...

  7. Atitit.软件按钮与仪表盘(13)--全文索引操作--db数据库子系统mssql2008

    Atitit.软件按钮与仪表盘(13)--全文索引操作--db数据库子系统mssql2008 全文索引操作 4.全文索引和like语句比较 1 5.倒排索引 inverted index 1 2.SQ ...

  8. Atitit.软件仪表盘(4)--db数据库子系统-监测

    Atitit.软件仪表盘(4)--db数据库子系统-监测 连接数::: 死锁表列表:死锁基础列表(最近几条记录,时间,sql等) 3.对服务器进行监控,获取CUP,I/O使用情况   4.对数据库进行 ...

  9. Atitit.软件仪表盘(4)--db数据库子系统-监測

    Atitit.软件仪表盘(4)--db数据库子系统-监測 连接数::: 死锁表列表:死锁基础列表(近期几条记录,时间,sql等) 3.对server进行监控.获取CUP.I/O使用情况   4.对数据 ...

随机推荐

  1. 彻底解决unable to find valid certification path to requested target

    安装证书. 下载证书 第一步是要下载证书 去你程序要访问的网站,点击那个锁按钮,并点击查看详情(chrome浏览器) 点击View certificate 点击详细信息 复制到文件 下一步 选择格式 ...

  2. css浮动float详解

    https://www.cnblogs.com/iyangyuan/archive/2013/03/27/2983813.html

  3. 【HCIA Gauss】学习汇总-数据库管理(事务 权限 审计 OBDC JDBC)-6

    事务控制事务提交 commit事务回滚 rollback savepoint 用于事务设置保存点 ----> savepoint s1 / savepoint s2 rollback to sa ...

  4. redis启动异常处理一例

    rm -rf /var/log/redis/redis.log echo "net.core.somaxconn= 1024" >> /etc/sysctl.conf ...

  5. CentOS7:sorry,that didn't work.please try again!

    参考以下解决方案,重点是vi etc/selinux/config 把 enforcing 改为 disable 应用场景 linux管理员忘记root密码,需要进行找回操作.注意事项:本文基于cen ...

  6. CefSharp 与 js 相互调用及注意事项

    CefSharp 与 js 相互调用 一. CefSharp调用 js CefSharp.WinForms.ChromiumWebBrowser wb; ... 方式1. ExecuteScriptA ...

  7. scala 中的匹配模式

    unapply 仅作匹配,不作其它输出.返回 Boolean 值 object UpperCase { def unapply(s: String): Boolean = s.toUpperCase ...

  8. centos7部署inotify与rsync实现实时数据同步

    实验环境:CentOS Linux release 7.6.1810 node1:192.168.216.130 客户端(向服务端发起数据同步) node2:192.168.216.132 服务端(接 ...

  9. Spring源码窥探之:单实例Bean的创建过程

    finishBeanFactoryInitialization(beanFactory);初始化剩下的所有的单实例(非懒加载)Bean(Instantiate all remaining (non-l ...

  10. django-缓存django-redis

    https://django-redis-chs.readthedocs.io/zh_CN/latest/ 安装 django-redis 最简单的方法就是用 pip : pip install dj ...