读书人

Sqlite 惯用函数封装:创建删除插

发布时间: 2013-01-21 10:15:39 作者: rapoo

Sqlite 常用函数封装:创建,删除,插入,表段、字段获取

以下是频繁用到的Sqlite函数,内容格式相对固定,封装一下有助于提高开发效率(^_^至少提高Codeeer的效率了)

而且,我发现Sqlite中文资料比较少,起码相对其他找起来要复杂些,服务一下大众~

我没有封装读取部分,因为数据库读取灵活性太大,封装起来难度也大,而且就算封装好了,也难以应付所有情况,还是建议根据实际情况设计代码逻辑。

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


创建

/// <summary>/// Get Words From Table->Sqlite/// </summary>/// <param name="TargetTable">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;}

读书人网 >SQL Server

热点推荐