Example #1
0
        private void button16_Click(object sender, EventArgs e)
        {
            //测试SQLite的创建表、插入数据
            try
            {
                string dbFileName = "SynCompany.db";
                string dbFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dbFileName);

                //如果不存在,则创建数据库
                SQLiteHelper.CreateDB(dbFilePath);

                //如果不存在此表,则创建表
                string        tableName        = "ReplaceString";
                List <string> tableColumnNames = new List <string>()
                {
                    "ActionCode", "ActionName", "ActionParamJson", "GroupCode", "TabCode", "ReplaceDate", "InputText", "ResultText"
                };
                if (!SQLiteHelper.CreateTable(dbFilePath, tableName, tableColumnNames))
                {
                    MessageBox.Show("创建数据库中的表失败!");
                }

                //插入数据
                Dictionary <string, object> dicTableColumnData = new Dictionary <string, object>();
                var i = SQLiteHelper.ExecuteInsert(tableName, ReplaceHistoryModelToDic(new ReplaceHistoryModel("ActionCode", "ActionParamJson", "Test", "", "", "", "")));

                //读取所有数据
                string cmdText01 = $"select * from {tableName}";
                var    a01       = SQLiteHelper.ExecuteDataSet(cmdText01);

                //带条件读取数据
                string cmdText = $"select * from {tableName} where {tableColumnNames[0]}=@{tableColumnNames[0]}";
                var    a       = SQLiteHelper.ExecuteDataSet(cmdText, "3223");
                //var b = SQLiteHelper.GetSchema();

                SQLiteHelper.CloseConnect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }