当前位置: 首页>>代码示例>>C#>>正文


C# SQLiteConnection.Execute方法代码示例

本文整理汇总了C#中System.Data.SQLite.SQLiteConnection.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.Execute方法的具体用法?C# SQLiteConnection.Execute怎么用?C# SQLiteConnection.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SQLite.SQLiteConnection的用法示例。


在下文中一共展示了SQLiteConnection.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateSampleSchema

 internal static void CreateSampleSchema(SQLiteConnection connection)
 {
     try { connection.Execute("DROP TABLE table1"); }
     catch { }
     try { connection.Execute("CREATE TABLE table1 (id integer primary key, name text)"); }
     catch { }
 }
开发者ID:einsof1031,项目名称:WindowsForms,代码行数:7,代码来源:DapperTest.cs

示例2: btnClear_Click

 private void btnClear_Click(object sender, EventArgs e)
 {
     using (var conn = new SQLiteConnection(Common.ConnectionString))
     {
         //清理无效远程主机
         conn.Execute(
             "DELETE FROM RemoteHost WHERE FParentId>0 AND FConectId NOT IN (SELECT FId FROM ConnectLib)");
         //清理无效父级节点
         conn.Execute(
             "DELETE FROM RemoteHost WHERE FParentId=0 AND FId NOT IN (SELECT FParentId FROM RemoteHost)");
     }
     LoadHostConfig();
 }
开发者ID:terrychan9527,项目名称:RemoteDesktopManage,代码行数:13,代码来源:MainForm.cs

示例3: TestDapper

        public void TestDapper()
        {
            var dataSource = @"test.sqlite";
            SQLiteConnection.CreateFile(dataSource);
            var builder = new SQLiteConnectionStringBuilder
            {
                DataSource = dataSource,
                LegacyFormat = false,
                Version = 3,
                SyncMode = SynchronizationModes.Off,
                JournalMode = SQLiteJournalModeEnum.Wal
            };

            using (var tran = new TransactionScope(TransactionScopeOption.Required))
            using (var connection = new SQLiteConnection(builder.ToString()))
            {
                connection.Open();
                CreateSampleSchema(connection);

                try
                {
                    connection.Execute("INSERT INTO table1 VALUES (@Id, @Name)", new { Id = 1, Name = "Name-1" });
                    connection.Execute("INSERT INTO table1 VALUES (@Id, @Name)", new { Id = 2, Name = "Name-2" });
                    connection.Execute("INSERT INTO table1 VALUES (@Id, @Name)", new { Id = 3, Name = "Name-3" });

                    dynamic dynamicObj = connection.Query("SELECT id, name FROM table1 LIMIT 1").FirstOrDefault();

                    Console.WriteLine("Id: {0}", dynamicObj.id);
                    Console.WriteLine("Name: {0}", dynamicObj.name);

                    var mappingObj = connection.Query<Table1>("SELECT id, name FROM table1 LIMIT 1").FirstOrDefault();

                    Console.WriteLine("Id: {0}", mappingObj.Id);
                    Console.WriteLine("Name: {0}", mappingObj.Name);

                    dynamic results = connection.Query("SELECT id, name FROM table1");
                    foreach (dynamic item in results)
                    {
                        Console.WriteLine(item);
                    }

                    tran.Complete();
                }
                catch
                {
                }
            }
        }
开发者ID:einsof1031,项目名称:WindowsForms,代码行数:48,代码来源:DapperTest.cs

示例4: AddProfile

 public void AddProfile(EmployeeProfile commandDto, string imgURL, string cartoonURL)
 {
     string user = System.Web.HttpContext.Current.User.Identity.Name;
     using (DbConnection conn = new SQLiteConnection(ConfigurationManager.ConnectionStrings["reedDirectory"].ConnectionString))
     {
         conn.Open();
         conn.Execute(
             "insert into EmployeeProfile (Department, FirstName, ImageUrl, LastName, Role, Tags, CreatedBy, CreatedOn, IsSuperUser, Extension, CartoonURL, WindowsIdentity, emailaddress, SeatingFloor, seatNo) values " +
             "(@Department, @FirstName, @ImageUrl, @LastName, @Role, @Tags, @CreatedBy, @CreatedOn, @IsSuperUser, @Extension, @CartoonURL, @WindowsIdentity, @emailAddress, @SeatingFloor, @seatNo)",
             new
                 {
                     Department = commandDto.Department,
                     FirstName = commandDto.FirstName.Replace("'","''"),
                     ImageUrl = imgURL,
                     LastName = commandDto.LastName.Replace("'", "''"),
                     Role = commandDto.Role,
                     Tags = !string.IsNullOrEmpty(commandDto.Tags) ? commandDto.Tags.Replace("'", "''"): "",
                     CreatedBy = user.Remove(0, 11),
                     CreatedOn = commandDto.CreatedOn,
                     IsSuperUser = false,
                     Extension = !string.IsNullOrEmpty(commandDto.Extension) ? commandDto.Extension.Replace("'", "''") : "",
                     CartoonURL = cartoonURL,
                     windowsIdentity = user,
                     emailAddress = commandDto.EmailAddress,
                     SeatingFloor = commandDto.SeatingFloor,
                     seatNo = commandDto.SeatNo
                 });
         conn.Close();
     }
 }
开发者ID:reedcouk,项目名称:wiki-toons,代码行数:30,代码来源:ImplEmployeeRepository.cs

示例5: ClearLogs

 private void ClearLogs()
 {
     using (var connection = new SQLiteConnection(ConnectionString))
     {
         connection.Execute("delete from Log");
     }
 }
开发者ID:jibedoubleve,项目名称:shell,代码行数:7,代码来源:DebugMenuViewModel.cs

示例6: Setup

        public virtual void Setup()
        {
            string connectionString = string.Format("Data Source=.\\dapperTest_{0}.sqlite", Guid.NewGuid());
            string[] connectionParts = connectionString.Split(';');
            string file = connectionParts
                .ToDictionary(k => k.Split('=')[0], v => v.Split('=')[1])
                .Where(d => d.Key.Equals("Data Source", StringComparison.OrdinalIgnoreCase))
                .Select(k => k.Value).Single();

            if (File.Exists(file))
            {
                File.Delete(file);
            }

            SQLiteConnection connection = new SQLiteConnection(connectionString);
            var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper<>), new List<Assembly>(), new SqliteDialect());
            var sqlGenerator = new SqlGeneratorImpl(config);
            Db = new Database(connection, sqlGenerator);

            var files = new List<string>
                                {
                                    ReadScriptFile("CreateAnimalTable"),
                                    ReadScriptFile("CreateFooTable"),
                                    ReadScriptFile("CreateMultikeyTable"),
                                    ReadScriptFile("CreatePersonTable"),
                                    ReadScriptFile("CreateCarTable")
                                };

            foreach (var setupFile in files)
            {
                connection.Execute(setupFile);
            }
        }
开发者ID:holer-h,项目名称:Dapper-Extensions,代码行数:33,代码来源:SqliteBaseFixture.cs

示例7: ModuleConfigurations

 public ModuleConfigurations()
 {
     db = new SQLiteConnection("Data Source=:memory:;Version=3;New=True");
     //todo: create platy table
     db.Open();
     db.Execute("PRAGMA foreign_keys=ON");
 }
开发者ID:smithed,项目名称:ConfigEditor2,代码行数:7,代码来源:ModuleConfiguration.cs

示例8: Execute

 public bool Execute(string connectionString, string sql)
 {
     using (var cnn = new SQLiteConnection(connectionString))
     {
         cnn.Open();
         return cnn.Execute(sql) > 0;
     }
 }
开发者ID:howbigbobo,项目名称:DailyCode,代码行数:8,代码来源:SqlExecutor.cs

示例9: LitePostRepository

 public LitePostRepository() 
 {
     using (var conn = new SQLiteConnection(Connectionstring))
     {
         conn.Open();
         conn.Execute(@" create table IF NOT EXISTS Posts (Id INTEGER PRIMARY KEY, Title nvarchar(255), Content nvarchar(1000) not null) ");
     }
 }
开发者ID:chenzuo,项目名称:MicroBlog,代码行数:8,代码来源:LitePostRepository.cs

示例10: CreateConnectionCore

 protected override DbConnection CreateConnectionCore()
 {
     var con = new SQLiteConnection(ConnectionStringBuilder.CreateWithFullUri(
            "file::memory:?cache=shared"));
     con.Open();
     con.Execute("PRAGMA case_sensitive_like=1");
     return con;
 }
开发者ID:Kei-Nanigashi,项目名称:StarryEyes,代码行数:8,代码来源:InMemoryDatabaseConnectionDescriptor.cs

示例11: btnSave_Click

        private void btnSave_Click(object sender, System.EventArgs e)
        {
            if (InfoIsError()) return;

            using (var conn = new SQLiteConnection(Common.ConnectionString))
            {
                if (IsModify)
                {
                    conn.Execute("UPDATE RemoteHost SET [email protected],[email protected],[email protected],[email protected] WHERE [email protected]",
                         new { name = txtName.Text, connectId = cbIpAddress.SelectedValue, parentId = chIsParent.Checked ? 0 : cbParent.SelectedValue, sort = numSort.Text, id = RemoteHost.FId });
                }
                else
                {
                    conn.Execute("INSERT INTO RemoteHost('FName','FConectId','FParentId','FSort') VALUES(@name,@connectId,@parentId,@sort)",
                        new { name = txtName.Text, connectId = cbIpAddress.SelectedValue, parentId = chIsParent.Checked ? 0 : cbParent.SelectedValue, sort = numSort.Text });
                }
            }
            DialogResult = DialogResult.OK;
        }
开发者ID:terrychan9527,项目名称:RemoteDesktopManage,代码行数:19,代码来源:RemoteForm.cs

示例12: CreateDb

        public void CreateDb()
        {
            using (var connection = new SQLiteConnection(ConnectionString))
            {
                var query = @"CREATE TABLE Init (Id INT NOT NULL)";

                connection.Open();
                connection.Execute(query);
            }
        }
开发者ID:alexbeletsky,项目名称:wonka,代码行数:10,代码来源:Bootstrapper.cs

示例13: SaveEvent

        public static void SaveEvent(EventInfo eventInfo)
        {
            using (var conn = new SQLiteConnection(_connectionString))
            {
                var query = @"  insert into EventInfo(WindowTitle, EventType)
                                values (@title, @type);";
                conn.Open();

                conn.Execute(query, new { title = eventInfo.WindowTitle, type = eventInfo.EventType }, null, null, null);
            }
        }
开发者ID:enriquein,项目名称:TimesheetHelper,代码行数:11,代码来源:DbAccess.cs

示例14: ModulesRepository

 public ModulesRepository(SQLiteConnection database)
 {
     this.db = database;
     lock(database) {
         if (db.State == System.Data.ConnectionState.Closed)
         {
             db.Open();
         }
     }
     db.Execute("PRAGMA foreign_keys=ON");
 }
开发者ID:smithed,项目名称:ConfigEditor2,代码行数:11,代码来源:RegisteredModules.cs

示例15: Set

        public void Set(IContent content)
        {
            string connString = ConfigurationManager.ConnectionStrings["WilliamsonFamilyConnectionString"].ConnectionString;
                    //var connection = new ProfiledDbConnection(new SQLiteConnection(connString), MiniProfiler.Current);
             using (var conn = new SQLiteConnection(connString))
             {
                 conn.Open();

                 var contentExists = conn.Query<Content>("SELECT * FROM Content WHERE Token = @token", new { @token = content.Token }, null, true, null, null).FirstOrDefault();
                 if (contentExists == null)
                     conn.Execute("INSERT INTO Content (Token, Value) VALUES (@Token, @Value)", new { @token = content.Token, @value = content.Value }, null, null, null);
                 else
                     conn.Execute(@"
            UPDATE Content
            SET Token = @Token,
            Value = @Value
            WHERE ContentID = @ContentID", new { @token = content.Token, @value = content.Value, @ContentID = content.ContentID }, null, null, null);

                 conn.Close();
             }
        }
开发者ID:sgwill,项目名称:familyblog,代码行数:21,代码来源:ContentRepository.cs


注:本文中的System.Data.SQLite.SQLiteConnection.Execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。