Ejemplo n.º 1
0
        public clsBaseConnection(string ConnectionString)
        {
            m_mustDisposeCN = true;
            m_Cnstr         = new SqlConnectionStringBuilder(ConnectionString);

            SqlDAC.SetCommandTimeOut(SqlDAC.TimeOut);
        }
Ejemplo n.º 2
0
 public clsBaseConnection()
 {
     if (m_Cnstr == null)
     {
         if (ConnectionString != "")
         {
             m_Cnstr = new SqlConnectionStringBuilder(ConnectionString);
         }
         else
         {
             m_Cnstr = new SqlConnectionStringBuilder();
         }
     }
     m_mustDisposeCN = true;
     SqlDAC.SetCommandTimeOut(200);
     LoadConnectionString();
 }
Ejemplo n.º 3
0
        private static string CreateTempTableFromDataTable(ref SqlConnection con, System.Data.DataTable dt)
        {
            Random rnd = new Random();
            string tbl = "##tbl_" + rnd.Next(10000).ToString();

            StringBuilder sbTempTable = new StringBuilder("CREATE TABLE " + tbl + "(");
            string        sColDef     = "";

            foreach (DataColumn col in dt.Columns)
            {
                switch (col.DataType.ToString())
                {
                case "System.Int64":
                    sColDef  = "[" + col.ColumnName + "] bigint ";
                    sColDef += (col.AutoIncrement) ? " Identity (" + col.AutoIncrementSeed.ToString() + "," + col.AutoIncrementStep.ToString() + ")," : ",";
                    sbTempTable.AppendLine(sColDef);
                    break;

                case "System.Int32":
                    sColDef  = "[" + col.ColumnName + "] int ";
                    sColDef += (col.AutoIncrement) ? " Identity (" + col.AutoIncrementSeed.ToString() + "," + col.AutoIncrementStep.ToString() + ")," : ",";
                    sbTempTable.AppendLine(sColDef);
                    break;

                case "System.DateTime":
                    sbTempTable.AppendLine("[" + col.ColumnName + "] datetime2, ");
                    break;

                case "System.String":
                    sColDef  = "[" + col.ColumnName + "] varchar( ";
                    sColDef += (col.MaxLength == -1) ? "max" : col.MaxLength.ToString();
                    sColDef += "), ";
                    sbTempTable.AppendLine(sColDef);
                    break;

                case "System.Single":
                    sbTempTable.AppendLine("[" + col.ColumnName + "] float , ");
                    break;

                case "System.Double":
                    sbTempTable.AppendLine("[" + col.ColumnName + "] float , ");
                    break;

                case "System.Int16":
                    sbTempTable.AppendLine("[" + col.ColumnName + "] smallint , ");
                    break;

                case "System.Boolean":
                    sbTempTable.AppendLine("[" + col.ColumnName + "] bit , ");
                    break;

                case "System.Decimal":
                    sbTempTable.AppendLine("[" + col.ColumnName + "] decimal(19,4) , ");
                    break;

                case "System.Byte":
                    sbTempTable.AppendLine("[" + col.ColumnName + "] tinyint, ");
                    break;

                case "System.Guid":
                    sbTempTable.AppendLine("[" + col.ColumnName + "] uniqueidentifier, ");
                    break;

                default:
                    throw new Exception("No definition for column type " + col.DataType.ToString());
                }
            }

            string pks = "";

            if (dt.PrimaryKey.Length > 0)
            {
                pks = "CONSTRAINT PK_" + tbl + " PRIMARY KEY (";
                for (int i = 0; i < dt.PrimaryKey.Length; i++)
                {
                    pks += dt.PrimaryKey[i].ColumnName + ",";
                }
                pks = pks.Substring(0, pks.Length - 1) + ")";
            }
            if (pks != "")
            {
                sbTempTable.AppendLine(pks);
            }
            else
            {
                sbTempTable.Remove(sbTempTable.Length - 1, 1);
            }
            sbTempTable.Append(")");

            int iTemp = SqlDAC.ExecuteNonQuery(con, CommandType.Text, sbTempTable.ToString(), null);

            return(tbl);
        }
Ejemplo n.º 4
0
 protected int ExecuteNonQuery(SqlConnection con, CommandType commandType, String commandText, params SqlParameter[] commandParameters)
 {
     return(SqlDAC.ExecuteNonQuery(con, commandType, commandText, commandParameters));
 }
Ejemplo n.º 5
0
 protected int ExecuteNonQuery(CommandType commandType, String commandText, params SqlParameter[] commandParameters)
 {
     return(SqlDAC.ExecuteNonQuery(m_Cnstr.ConnectionString, commandType, commandText, commandParameters));
 }
Ejemplo n.º 6
0
 protected object ExecuteScalar(CommandType commandType, String commandText,
                                params SqlParameter[] commandParameters)
 {
     return(SqlDAC.ExecuteScalar(m_Cnstr.ConnectionString, commandType, commandText, commandParameters));
 }
Ejemplo n.º 7
0
 protected DataSet ExecuteDataset(SqlConnection con, CommandType commandType, String commandText, params SqlParameter[] commandParameters)
 {
     return(SqlDAC.ExecuteDataset(con, commandType, commandText, commandParameters));
 }
Ejemplo n.º 8
0
 protected DataSet ExecuteDataset(CommandType commandType, String commandText, params SqlParameter[] commandParameters)
 {
     return(SqlDAC.ExecuteDataset(m_Cnstr.ConnectionString, commandType, commandText, commandParameters));
 }
Ejemplo n.º 9
0
 protected SqlDataReader ExecuteReader(CommandType commandType,
                                       String commandText,
                                       params SqlParameter[]  commandParameters)
 {
     return(SqlDAC.ExecuteReader(m_Cnstr.ConnectionString, commandType, commandText, commandParameters));
 }