Пример #1
0
 /// <summary>
 /// Stored proc insert with ID.
 /// </summary>
 /// <typeparam name="T">The type of object</typeparam>
 /// <typeparam name="U">The Type of the ID</typeparam>
 /// <param name="procName">Name of the proc.</param>
 /// <param name="parms">instance of DynamicParameters class. This        should include a defined output parameter</param>
 /// <returns>U - the @@Identity value from output parameter</returns>
 public static U StoredProcInsertWithID <T, U>(string procName, DynamicParameters parms, string connectionName = null)
 {
     using (SqlConnection connection = SqlMapperUtil.GetOpenConnection(connectionName))
     {
         var x = connection.Execute(procName, (object)parms, commandType: CommandType.StoredProcedure);
         return(parms.Get <U>("@ID"));
     }
 }
Пример #2
0
        private void InitDataBase(string dbName)
        {
            conStr = ConfigurationManager.AppSettings["ConString"];
            SqlMapperUtil.GetOpenConnection(conStr);
            string exsitsDB = "select count(1) from sys.sysdatabases where name =@dbName";
            int    result   = SqlMapperUtil.SqlWithParamsSingle <int>(exsitsDB, new { dbName = dbName });

            if (result == 0)
            {
                string s1  = " create database [" + dbName + "]";
                int    ret = SqlMapperUtil.InsertUpdateOrDeleteSql(s1, null);
            }
            conStr = conStr.Replace("master", dbName);
            var StaticStructAndFn = Path.Combine(Directory.GetCurrentDirectory(), "StaticStructAndFn.tsql");
            var sqls = File.ReadAllText(StaticStructAndFn);

            SqlServerHelper.ExecuteSql(sqls, conStr);
            string kjqjInsert = "delete dbo.kjqj where Projectid='{0}'  " +
                                " insert  dbo.kjqj(ProjectID,CustomerCode,CustomerName,BeginDate,EndDate,KJDate)" +
                                "  select '{0}','{1}','{1}','{2}','{3}','{4}'";

            SqlServerHelper.ExecuteSql(string.Format(kjqjInsert, dbName, _projectID, _beginDate, _endDate, _auditYear), conStr);
        }