参考“System.ArgumentException”类型的第一次机会异常在 System.Data.dll 中发生
混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集
SQLite 之 C#版 System.Data.SQLite 使用
“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;";
//加载sql
SQLiteCommand 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";
//加载sql
SQLiteCommand 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 获取数字用getint32
Console.Write(p + "\n");
}
/* cnn.Open();
string sql = "select * from tb_c2cMsg_1030331506";
SQLiteCommand cmd = cnn.CreateCommand();
cmd.CommandText = sql;
SQLiteDataReader reader = cmd.ExecuteReader();
//List<ImportInfo> infoList = new List<ImportInfo>();
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 });
}
*/
}
}
}