コード例 #1
0
        /// <summary>
        /// Translates an OleDb data table data to table data.
        /// </summary>
        /// <param name="dataTable">The datatable containing the data.</param>
        /// <returns>The translated data table</returns>
        public DataTable TranslateFunctionColumns(DataTable dataTable)
        {
            DataTable newTable = new DataTable("TableName");

            newTable.Columns.Add("ColumnName", typeof(String));
            newTable.Columns.Add("ColumnType", typeof(String));
            newTable.Columns.Add("ColumnNullable", typeof(Boolean));
            newTable.Columns.Add("ColumnOrder", typeof(Int32));
            newTable.Columns.Add("Length", typeof(Int64));
            newTable.Columns.Add("Precision", typeof(Int64));
            newTable.Columns.Add("IsOutParameter", typeof(Boolean));

            // For each row founs.
            foreach (DataRow row in dataTable.Rows)
            {
                // Create a new data row.
                DataRow rowNew = null;
                rowNew = newTable.NewRow();

                rowNew["ColumnName"]     = row["PARAMETER_NAME"];
                rowNew["ColumnType"]     = LinqToDataTypes.GetOleDbType(row["DATA_TYPE"].ToString());
                rowNew["ColumnNullable"] = row["IS_NULLABLE"];
                rowNew["ColumnOrder"]    = row["ORDINAL_POSITION"];
                rowNew["Length"]         = row["CHARACTER_MAXIMUM_LENGTH"];
                rowNew["Precision"]      = row["NUMERIC_PRECISION"];
                rowNew["IsOutParameter"] = (row["PARAMETER_TYPE"].ToString() == "4" ? true : false);

                // Add the current row to the table.
                newTable.Rows.Add(rowNew);
            }

            // Return the translated table.
            return(newTable);
        }
コード例 #2
0
        /// <summary>
        /// Translates an OleDb data table data to table data.
        /// </summary>
        /// <param name="dataTable">The datatable containing the data.</param>
        /// <param name="dataTableEx">The datatable containing the table data.</param>
        /// <returns>The translated data table</returns>
        public DataTable TranslateTableReferenceKey(string tableName, string owner, DataTable dataTable, DataTable dataTableEx)
        {
            DataTable newTable = new DataTable("TableName");

            newTable.Columns.Add("TableName", typeof(String));
            newTable.Columns.Add("ColumnName", typeof(String));
            newTable.Columns.Add("ColumnType", typeof(String));
            newTable.Columns.Add("IsNullable", typeof(Boolean));
            newTable.Columns.Add("Length", typeof(Int64));
            newTable.Columns.Add("Precision", typeof(Int64));
            newTable.Columns.Add("ForeignKeyTable", typeof(String));
            newTable.Columns.Add("ForeignKeyColumnName", typeof(String));
            newTable.Columns.Add("ForeignKeyOwner", typeof(String));

            // For each row found.
            foreach (DataRow row in dataTable.Rows)
            {
                if (row["PK_TABLE_NAME"].ToString() == tableName)
                {
                    DataRow columNames = null;
                    try{
                        columNames = dataTableEx.Select("COLUMN_NAME = '" + row["FK_COLUMN_NAME"] + "'").First();
                    }
                    catch { }

                    if (columNames == null)
                    {
                        columNames = dataTableEx.Select("COLUMN_NAME = '" + row["PK_COLUMN_NAME"] + "'").First();
                    }

                    // Create a new data row.
                    DataRow rowNew = null;
                    rowNew = newTable.NewRow();

                    rowNew["TableName"]            = row["FK_TABLE_NAME"];
                    rowNew["ColumnName"]           = row["FK_COLUMN_NAME"];
                    rowNew["ColumnType"]           = LinqToDataTypes.GetOleDbType(columNames["DATA_TYPE"].ToString());
                    rowNew["IsNullable"]           = columNames["IS_NULLABLE"];
                    rowNew["Length"]               = columNames["CHARACTER_MAXIMUM_LENGTH"];
                    rowNew["Precision"]            = columNames["NUMERIC_PRECISION"];
                    rowNew["ForeignKeyTable"]      = row["PK_TABLE_NAME"].ToString();
                    rowNew["ForeignKeyColumnName"] = row["PK_COLUMN_NAME"];
                    rowNew["ForeignKeyOwner"]      = row["PK_TABLE_SCHEMA"];

                    // Add the current row to the table.
                    newTable.Rows.Add(rowNew);
                }
            }

            // Return the translated table.
            return(newTable);
        }