예제 #1
0
        //constructor
        public TableInfo(string name, ETDataConnection gConn)
        {
            this.Name  = name;
            this.gConn = gConn;

            Colums = new List <ColumnInfo>();

            // lấy danh sách cột
            string strQuery = "select * " +
                              "from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='" + Name + "'";
            DataTable dt = gConn.GetDataTable(strQuery);

            // lấy danh sách các cột là khóa chính
            strQuery   = "select COLUMN_NAME from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE where TABLE_NAME = '" + Name + "' and CONSTRAINT_NAME like N'PK_%'";
            PrimaryKey = gConn.ExecuteScalar(strQuery).ToString();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ColumnInfo column = new ColumnInfo();
                column.Name     = dt.Rows[i]["COLUMN_NAME"].ToString();
                column.DataType = dt.Rows[i]["DATA_TYPE"].ToString();
                if (dt.Rows[i]["CHARACTER_MAXIMUM_LENGTH"].ToString() != "")
                {
                    column.MaxValue = int.Parse(dt.Rows[i]["CHARACTER_MAXIMUM_LENGTH"].ToString());
                }
                else
                {
                    column.MaxValue = 0;
                }

                if (dt.Rows[i]["NUMERIC_PRECISION"].ToString() != "")
                {
                    column.NumericPrecision = int.Parse(dt.Rows[i]["NUMERIC_PRECISION"].ToString());
                }
                else
                {
                    column.NumericPrecision = 0;
                }

                if (dt.Rows[i]["NUMERIC_SCALE"].ToString() != "")
                {
                    column.NumericScale = int.Parse(dt.Rows[i]["NUMERIC_SCALE"].ToString());
                }
                else
                {
                    column.NumericScale = 0;
                }

                column.Default = dt.Rows[i]["COLUMN_DEFAULT"].ToString();

                if (column.Name != PrimaryKey)
                {
                    Colums.Add(column);
                }
            }
            this.StoredProcedure = "";
            this.SpSelect        = GenerateStoredProcedureGetFilter(this);
            this.SpAddUpdate     = GenerateStoredProcedureAddUpdate(this);
        }
예제 #2
0
 private bool TestConnection(DatabaseModel serverInfo)
 {
     try
     {
         ETDataConnection gConn = new ETDataConnection(GetConnectionString(serverInfo));
         int test = int.Parse(gConn.ExecuteScalar("select 10").ToString());
         if (test == 10)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }