c#连接sqlite数据库读取内容
参考“System.ArgumentException”类型的第一次机会异常在 System.Data.dll 中发生
C# 读取sqlite文件
用 C# 访问 SQLite 入门
混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集
SQLite 之 C#版 System.Data.SQLite 使用
C#与数据库SQLite:在C#项目中使用SQLite
实现在C#中通过语句,查询数据库中的数据
“System.ArgumentException”类型的第一次机会异常在 System.Data.dll 中发生
关于c#中SqlDataReader的GetString()方法的疑惑.
sqldataread 中 getstring()方法的使用
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SQLite;namespace qq
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){//创建连接字符串string databaseFileName = "C:/QQ.db";string connectionString = "data source = " + databaseFileName;//链接数据库SQLiteConnection dbConnection = new SQLiteConnection(connectionString);//打开数据库dbConnection.Open();//sql语句string sql = "select name from sqlite_master where type='table' order by name;";//加载sqlSQLiteCommand cd = new SQLiteCommand(sql, dbConnection);//执行SQLiteDataReader dr = cd.ExecuteReader();while (dr.Read())//读取{Console.Write(dr["name"]);}}private void listView1_SelectedIndexChanged(object sender, EventArgs e){//创建连接字符串string databaseFileName = "C:/QQ.db";string connectionString = "data source = " + databaseFileName;//链接数据库SQLiteConnection dbConnection = new SQLiteConnection(connectionString);//打开数据库dbConnection.Open();//sql语句string sql = "select * from tb_c2cMsg_1030331506";//加载sqlSQLiteCommand cd = new SQLiteCommand(sql, dbConnection);//执行SQLiteDataReader dr = cd.ExecuteReader();while (dr.Read())//读取{DateTime d = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));//将时间戳转年月日long t = long.Parse(dr["time"] + "0000000");TimeSpan to = new TimeSpan(t);Console.Write(d.Add(to) + "\n");var time6 = d.Add(to);ListViewItem lt = new ListViewItem();//将数据库数据转变成ListView类型的一行数据lt.Text = dr["uin"].ToString();lt.SubItems.Add(time6.ToString());//lt.SubItems.Add(dr["pwd"].ToString());//将lt数据添加到listView1控件中listView1.Items.Add(lt);int panduan = dr.GetInt32(4);//Console.Write(panduan);if (panduan == 1){Console.Write("对方");}else{Console.Write("我");}//var tempStr =dr["time"];var p = dr["content"];//获取纯文本用getstring 获取序号用getordinal 获取数字用getint32Console.Write(p + "\n");}/* cnn.Open();string sql = "select * from tb_c2cMsg_1030331506";SQLiteCommand cmd = cnn.CreateCommand();cmd.CommandText = sql;SQLiteDataReader reader = cmd.ExecuteReader();//List infoList = new List();while (reader.Read()){// ImportInfo info = new ImportInfo();var tempStr = reader.GetString(4);Console.Write(tempStr);//dynamic jsonInfos = JsonConvert.DeserializeObject(tempStr);//var episode_title = jsonInfos.episode_title.ToString();//var audio_file_name = jsonInfos.audio_file_name.ToString();//var lrc_file_name = jsonInfos.lrc_file_name.ToString();//infoList.Add(new ImportInfo() { data1 = data1, data2 = data2 });}*/ }}
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
