本文整理汇总了C#中DataAccess.GetDataTable方法的典型用法代码示例。如果您正苦于以下问题:C# DataAccess.GetDataTable方法的具体用法?C# DataAccess.GetDataTable怎么用?C# DataAccess.GetDataTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataAccess
的用法示例。
在下文中一共展示了DataAccess.GetDataTable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CombineAllTalbeScripts
public static void CombineAllTalbeScripts(string codeRootPath, string connectionString)
{
string scriptPath = Path.Combine(codeRootPath, "tables");
string script =
" DECLARE @totalTableCount int " +
" DECLARE @tableListCount int " +
" " +
" DECLARE @tableList TABLE " +
" (tableID int) " +
" " +
" SELECT @totalTableCount = COUNT(1) FROM sys.tables " +
" " +
" INSERT INTO @tableList " +
" SELECT object_id FROM sys.tables " +
" WHERE object_id NOT IN " +
" (SELECT parent_object_id FROM sys.foreign_keys) " +
" ORDER BY [name] " +
" " +
" WHILE (EXISTS( " +
" select * from sys.foreign_keys " +
" WHERE parent_object_id NOT in " +
" (SELECT parent_object_id FROM sys.foreign_keys keys LEFT JOIN @tableList tbl ON keys.referenced_object_id = tbl.tableID " +
" WHERE tbl.tableID is null) " +
" AND referenced_object_id IN (SELECT tableID FROM @tableList) " +
" AND parent_object_id NOT IN (SELECT tableID FROM @tableList) " +
" )) " +
" BEGIN " +
" INSERT INTO @tableList " +
" SELECT distinct parent_object_id FROM sys.foreign_keys " +
" WHERE parent_object_id NOT in " +
" (SELECT parent_object_id FROM sys.foreign_keys keys LEFT JOIN @tableList tbl ON keys.referenced_object_id = tbl.tableID " +
" WHERE tbl.tableID is null) " +
" AND referenced_object_id IN (SELECT tableID FROM @tableList) " +
" AND parent_object_id NOT IN (SELECT tableID FROM @tableList) " +
" END " +
" " +
" INSERT INTO @tableList " +
" SELECT parent_object_id FROM sys.foreign_keys " +
" WHERE parent_object_id NOT IN " +
" (SELECT tableID FROM @tableList) " +
" ORDER BY [name] " +
" " +
" " +
" SELECT tableID, name FROM @tableList l INNER JOIN sys.tables t ON l.tableID=t.object_id and t.name not like 'DEL_%' ";
DataAccess da = new DataAccess(connectionString, ProviderType.Sql);
da.CommandText = script;
da.CommandType = CommandType.Text;
DataTable dt = da.GetDataTable();
StringBuilder sb = new StringBuilder();
foreach (DataRow row in dt.Rows)
{
string path = string.Format("{0}.sql", row["name"]);
path = Path.Combine(scriptPath, path);
if (File.Exists(path))
{
sb.AppendFormat("PRINT '**************** {0} *******************'", row["name"]).AppendLine();
sb.AppendLine(File.ReadAllText(path));
}
}
string dest = Path.Combine(codeRootPath, "alltables.sql");
File.WriteAllText(dest, sb.ToString());
}
示例2: GetBaseName
/// <summary>
/// Obtiene el nombre de la base de datos actual.
/// </summary>
/// <param name="oDA">Conexión actual.</param>
/// <returns>Nombre de la Base de Datos.</returns>
public static string GetBaseName(DataAccess oDA)
{
try {
DataTable dt = null;
oDA.ClearParameters();
dt = oDA.GetDataTable("SELECT DB_NAME()");
return dt.Rows[0][0].ToString();
} catch (DataAccessException ex) {
throw new CoreException(ex.Message, ex);
} catch (Exception ex) {
throw new CoreException("Error no esperado al obtener el nombre de la Base.", ex);
}
}
示例3: GenerateAllRDScripts
public static void GenerateAllRDScripts(string codeRootPath)
{
string conn = "server=10.22.12.43;uid=SCIToolTeam;pwd=SciTool!;database=ResponseDriver;";
string script = "";
string type = "";
DataTable results = new DataTable();
DataTable dt;
DataTable dtTemp;
results.Columns.Add("Type");
results.Columns.Add("Name");
results.Columns.Add("Script");
DataAccess da = new DataAccess(conn, ProviderType.Sql);
#region scripts except foreign key
da.CommandType = System.Data.CommandType.Text;
da.CommandText = "SELECT * FROM sys.objects ORDER BY [type], [name]";
dt = da.GetDataTable();
int i = 0;
foreach (DataRow row in dt.Rows)
{
i++;
Console.WriteLine("Processing {0:d4}: {1}.{2}", i, row["Type"], row["Name"]);
switch (row["Type"].ToString().Trim())
{
case "D": //default value is set in table script
case "F": //FOREIGN KEY
case "PK": //primary key is set in table script
case "S": //SYSTEM_TABLE
type = "";
break;
case "FN": //SQL_SCALAR_FUNCTION
case "IF": //SQL_INLINE_TABLE_VALUED_FUNCTION
case "TF": //SQL_TABLE_VALUED_FUNCTION
type = "Functions";
break;
case "P": //SQL_STORED_PROCEDURE
type = "Stored Procedures";
break;
case "TR": //SQL_TRIGGER
type = "Triggers";
break;
case "V": //VIEW
type = "Views";
break;
case "FS": //CLR_SCALAR_FUNCTION
type = "CLR Functions";
break;
case "PC": //CLR_STORED_PROCEDURE
type = "CLR Stored Procedures";
break;
case "U":
type = "Tables";
break;
case "UQ":
type = "Unique Index";
break;
}
switch (row["Type"].ToString().Trim())
{
case "D": //default value is set in table script
case "F": //FOREIGN KEY
case "PK": //primary key is set in table script
case "S": //SYSTEM_TABLE
case "IT":
case "SQ":
script = null;
break;
case "FS": //CLR_SCALAR_FUNCTION
case "PC": //CLR_STORED_PROCEDURE
script = "Encrypted";
break;
case "FN": //SQL_SCALAR_FUNCTION
case "IF": //SQL_INLINE_TABLE_VALUED_FUNCTION
case "P": //SQL_STORED_PROCEDURE
case "TF": //SQL_TABLE_VALUED_FUNCTION
case "TR": //SQL_TRIGGER
case "V": //VIEW
//script = null;
script = "sp_helptext " + row["Name"].ToString();
da.CommandText = script;
dtTemp = da.GetDataTable();
script = "";
foreach (DataRow rowTemp in dtTemp.Rows)
{
script += rowTemp[0];
}
break;
case "U":
script =
#region generate create table script
"declare @table sysname " +
"set @table = '{0}' " +
//.........这里部分代码省略.........