Sqlite 常用函数封装提高Codeeer的效率(2)


List<Sqlite.InsertBag> Lst = new List<Sqlite.InsertBag>();
Lst.Add(new Sqlite.InsertBag("W2", "222222222"));
Lst.Add(new Sqlite.InsertBag("W44", "4444444"));
Sqlite.Insert(@"D:\1.Sql3", "TableTest", Lst);


表段获取

复制代码 代码如下:


/// <summary>
/// Get Tables From Sqlite
/// </summary>
/// <returns>list of Tables</returns>
public static List<string> GetTables(string DataSource)
{
List<string> ResultLst = new List<string>();
using (SQLiteConnection conn = new SQLiteConnection("Data Source=" + DataSource))
{
conn.Open();
using (SQLiteCommand tablesGet = new SQLiteCommand("SELECT name from sqlite_master where type='table'", conn))
{
using (SQLiteDataReader tables = tablesGet.ExecuteReader())
{
while (tables.Read())
{
try
{
ResultLst.Add(tables[0].ToString());
}
catch (Exception E)
{
MessageBox.Show(E.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
}
return ResultLst;
}


字段获取

复制代码 代码如下:


/// <summary>
/// Get Words From Table->Sqlite
/// </summary>
/// <param>Target Table</param>
/// <returns>list of Words</returns>
public static List<string> GetWords(string DataSource,string TargetTable)
{
List<string> WordsLst = new List<string>();
using (SQLiteConnection conn = new SQLiteConnection("Data Source=" + DataSource))
{
conn.Open();
using (SQLiteCommand tablesGet = new SQLiteCommand(@"SELECT * FROM " + TargetTable, conn))
{
using (SQLiteDataReader Words = tablesGet.ExecuteReader())
{
try
{
for (int i = 0; i < Words.FieldCount; i++)
{
WordsLst.Add(Words.GetName(i));
}
}
catch (Exception E)
{
MessageBox.Show(E.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
return WordsLst;
}


解释下,为啥代码中的注释基本都用英文写了,因为这段时间在学双拼- -。可是还不太熟悉,打字超慢,而且Code的时候容易打断思路,好在~英文不多,而且这些都看不懂的话你……你要向我解释一下你是怎么一路学到数据库的 0。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjdjpd.html