本文整理汇总了C#中DBHelper.ExecuteTable方法的典型用法代码示例。如果您正苦于以下问题:C# DBHelper.ExecuteTable方法的具体用法?C# DBHelper.ExecuteTable怎么用?C# DBHelper.ExecuteTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBHelper
的用法示例。
在下文中一共展示了DBHelper.ExecuteTable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnOutputOK_Click
/// <summary>
/// 执行导出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnOutputOK_Click(object sender, EventArgs e)
{
try
{
StringBuilder sb = new StringBuilder();
foreach (object item in OutputList.SelectedItems)
{
XmlElement ele = docoper.QueryEle(string.Format("/Base/Output/Item[@Name='{0}']", item));
DBHelper operDB = new DBHelper(dataSourceList[ele.GetAttribute("DataBase")], providerName);
sb.AppendFormat(@"Use [{0}]
", operDB.DataBaseName);
if (cbxOutputDelete.Checked)
sb.AppendFormat(@"{0}
", FileStreamHelper.ReadText(string.Format("{0}{1}{2}\\Delete", Application.StartupPath, outputDataPath, ele.GetAttribute("Name"))));
sb.Append(SqlHelper.CreateInsertSql(ele.GetAttribute("Table"),
operDB.ExecuteTable(FileStreamHelper.ReadText(
string.Format("{0}{1}{2}\\Select", Application.StartupPath, outputDataPath, ele.GetAttribute("Name"))))));
sb.Append(@"
");
}
SaveText(sb.ToString());
MessageBox.Show("导出成功");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
示例2: DoStructDiffExecute
/// <summary>
/// 生成结构比对结果
/// </summary>
/// <param name="fromtable">原始表</param>
/// <param name="sourceonly">存在于原始表,但不存在与目标表的字段</param>
/// <param name="sourcealter">原始表中与目标表不同的字段</param>
/// <param name="totable">目标表</param>
/// <param name="targetonly">存在于目标表,但不存在与原始表的字段</param>
/// <param name="targetalter">目标表中与原始表不同的字段</param>
/// <returns>带if else的添加修改字段语句</returns>
private string DoStructDiffExecute(string fromtable, string totable)
{
//目标表中与原始表有差异的字段
IEnumerable<DataRow> targetdif = DataCompareHelper.QueryDiffRows(dataSourceList[DataSetFrom], "syscolumns", providerName, string.Format("id=object_id('{0}')", fromtable), dataSourceList[DataSetTo], "syscolumns", providerName, string.Format("id=object_id('{0}')", totable), "name,xtype,length,xprec,xscale", "name");
//原始表中与目标表有差异的字段
IEnumerable<DataRow> sourcedif = DataCompareHelper.QueryDiffRows(dataSourceList[DataSetTo], "syscolumns", providerName, string.Format("id=object_id('{0}')", totable), dataSourceList[DataSetFrom], "syscolumns", providerName, string.Format("id=object_id('{0}')", fromtable), "name,xtype,length,xprec,xscale", "name");
DBHelper dbfrom = new DBHelper(dataSourceList[DataSetFrom], providerName);
DBHelper dbto = new DBHelper(dataSourceList[DataSetTo], providerName);
//所有原始表的字段
var columnsFrom = dbfrom.ExecuteTable(string.Format(columnSearchSql, fromtable)).AsEnumerable();
//所有目标表的字段
var columnsTo = dbto.ExecuteTable(string.Format(columnSearchSql, totable)).AsEnumerable();
//存在于原始表,但不存在与目标表的字段
var sourceonly = from sd in sourcedif
join ct in columnsTo
on sd.Field<string>("name") equals ct.Field<string>("name") into temp
from tp in temp.DefaultIfEmpty()
where tp == null
select sd;
//存在于目标表,但不存在与原始表的字段
var targetonly = from td in targetdif
join cf in columnsFrom
on td.Field<string>("name") equals cf.Field<string>("name") into temp
from tp in temp.DefaultIfEmpty()
where tp == null
select td;
//原始表中与目标表不同的字段
var sourcealter = sourcedif.Except(sourceonly);
//目标表中与原始表不同的字段
var targetalter = targetdif.Except(targetonly);
return (sourceonly.Count() == 0 && targetonly.Count() == 0 && sourcealter.Count() == 0 && targetalter.Count()==0)
?string.Empty:string.Format(@"
/***存在于原始表,但不存在与目标表的字段***/
{0}
/***原始表中与目标表不同的字段***/
{1}
/***存在于目标表,但不存在与原始表的字段***/
{2}
/***目标表中与原始表不同的字段***/
{3}
"
, string.Join(@"
", sourceonly.Select(c => SqlHelper.CreateColumnSql(fromtable, c[0].ToString(), DbTool.GetColumnType(Convert.ToByte(c[1]), Convert.ToInt16(c[2]), Convert.ToByte(c[3]), Convert.ToByte(c[4])))).ToArray())
, string.Join(@"
", sourcealter.Select(c => SqlHelper.CreateColumnSql(totable, c[0].ToString(), DbTool.GetColumnType(Convert.ToByte(c[1]), Convert.ToInt16(c[2]), Convert.ToByte(c[3]), Convert.ToByte(c[4])))).ToArray())
, string.Join(@"
", targetonly.Select(c => SqlHelper.CreateColumnSql(totable, c[0].ToString(), DbTool.GetColumnType(Convert.ToByte(c[1]), Convert.ToInt16(c[2]), Convert.ToByte(c[3]), Convert.ToByte(c[4])))).ToArray())
, string.Join(@"
", targetalter.Select(c => SqlHelper.CreateColumnSql(totable, c[0].ToString(), DbTool.GetColumnType(Convert.ToByte(c[1]), Convert.ToInt16(c[2]), Convert.ToByte(c[3]), Convert.ToByte(c[4])))).ToArray()));
}