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


C# DbConnection.ExecuteNonQuery方法代码示例

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


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

示例1: CreateSchema

        ///<summary>Appends SQL statements to create a schema.  The SqlCommand will have a SqlSchema parameter.</summary>
        protected virtual void CreateSchema(DbConnection connection, SchemaMapping mapping)
        {
            if (connection == null) throw new ArgumentNullException("connection");
            if (mapping == null) throw new ArgumentNullException("mapping");

            connection.ExecuteNonQuery(@"
                IF schema_id(@SqlSchemaName) IS NULL
                    EXECUTE('create schema ' + @EscapedSchemaName);",
                new { mapping.SqlSchemaName, EscapedSchemaName = mapping.SqlSchemaName.EscapeSqlIdentifier() }
            );
        }
开发者ID:ShomreiTorah,项目名称:Libraries,代码行数:12,代码来源:SqlServerSqlProvider.cs

示例2: CreateCallListSheet

        static void CreateCallListSheet(DbConnection connection, string sheetName, IEnumerable<MelaveMalkaInvitation> callees)
        {
            Program.LoadTable<MelaveMalkaSeat>();
            connection.ExecuteNonQuery(@"
            CREATE TABLE [" + sheetName + @"] (
            [Last Name]	NVARCHAR(128),
            [His Name]	NVARCHAR(128),
            [Her Name]	NVARCHAR(128),
            [Address]	NVARCHAR(128),
            [Phone]		NVARCHAR(128),
            [Caller]	NVARCHAR(128),
            [Last Year]	NVARCHAR(64),
            [Seats]		NVARCHAR(64)
            );");

            foreach (var callee in callees.OrderBy(s => s.Person.LastName)) {
                var person = callee.Person;
                connection.ExecuteNonQuery(
                    @"INSERT INTO [" + sheetName + @"]
            ([Last Name],	[His Name],	[Her Name],	[Address],	[Phone],	[Caller],	[Last Year],	[Seats])
            VALUES	(@LastName,		@HisName,	@HerName,	@Address,	@Phone,		@Caller,	@LastAds,		@LastSeats);",
                    new {
                    person.LastName,
                    person.HisName,
                    person.HerName,

                    person.Address,
                    person.Phone,

                    Caller = (callee.Caller == null) ? "(none)" : callee.Caller.ToString(),
                    LastAds = person.Pledges
                                        .Where(p => p.ExternalSource == "Journal " + (callee.Year - 1))
                                        .Select(p => Names.AdTypes.FirstOrDefault(a => a.PledgeSubType == p.SubType))
                                        .Select(t => t == null ? "(other)" : t.Name)    // Handle custom pledges with unrecognized subtypes
                                        .DefaultIfEmpty(person.Invitees.Any(i => i.Year == callee.Year - 1) ? "(no ad)" : "(not invited)")
                                        .Join(", "),

                    LastSeats = person.MelaveMalkaSeats
                                        .Where(s => s.Year == callee.Year - 1)
                                        .Select(s => "M: " + s.MensSeats + ", " + "W: " + s.WomensSeats)
                                        .FirstOrDefault() ?? ""
                }
                );
            }
        }
开发者ID:SyedArifulIslamEmon,项目名称:Billing,代码行数:45,代码来源:ExcelExporter.cs

示例3: CreateTable

        ///<summary>Creates a table for the given schema mapping.</summary>
        ///<remarks>In addition to the columns in the SchemaMapping, a RowVersion column will be created.</remarks>
        public void CreateTable(DbConnection connection, SchemaMapping schema, IEnumerable<SchemaMapping> parentSchemas)
        {
            if (connection == null) throw new ArgumentNullException("connection");
            if (schema == null) throw new ArgumentNullException("schema");
            CreateSchema(connection, schema);

            var sql = new StringBuilder();

            //CREATE TABLE [SchemaName].[TableName] (
            //	[FirstColumn]	TYPE	NOT NULL,
            //	[SecondColumn]	TYPE	NULL,
            //	[RowVersion]	RowVersion
            //);

            sql.Append("CREATE TABLE ").Append(QualifyTable(schema)).AppendLine("(");

            foreach (var column in schema.Columns) {
                if (column == schema.PrimaryKey)
                    AppendPrimaryKey(sql, column);
                else if (column.Column is ForeignKeyColumn)
                    AppendForeignKey(sql, column, parentSchemas);
                else
                    AppendColumn(sql, column);

                sql.AppendLine(",");	//Even the last column gets a comma, because of the RowVersion column
            }

            sql.AppendLine("\t[RowVersion]\t\tRowVersion");
            sql.AppendLine(");");

            connection.ExecuteNonQuery(sql.ToString());
        }
开发者ID:ShomreiTorah,项目名称:Libraries,代码行数:34,代码来源:SqlServerSqlProvider.cs


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