本文整理汇总了C#中DBConnection.GetDataAdapter方法的典型用法代码示例。如果您正苦于以下问题:C# DBConnection.GetDataAdapter方法的具体用法?C# DBConnection.GetDataAdapter怎么用?C# DBConnection.GetDataAdapter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnection
的用法示例。
在下文中一共展示了DBConnection.GetDataAdapter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTable
private DataTable GetTable(string TableName, DBConnection dbcn)
{
DataTable dataTable = new DataTable(TableName);
string strSelect = "select * from " + TableName + " where 1<>1";
DbDataAdapter adapter = dbcn.GetDataAdapter(strSelect, true, false, false);
adapter.Fill(dataTable);
dataTable.ExtendedProperties.Add("da", adapter);
return dataTable;
}
示例2: SaveDataToSQlDB
private void SaveDataToSQlDB(SMDataSource smDS, ref DataSet ds)
{
int count = ds.Tables.Count;
DBConnection connection = new DBConnection(smDS);
connection.Open();
string str = null;
if (ds.ExtendedProperties.ContainsKey("CascadeSql"))
{
str = (string) ds.ExtendedProperties["CascadeSql"];
}
try
{
IDbTransaction transaction = connection.BeginTrasaction();
for (int i = 0; i < count; i++)
{
DataTable dataTable = ds.Tables[i];
if (dataTable.GetChanges() != null)
{
string strSelect = (string) dataTable.ExtendedProperties["selectsql"];
DbDataAdapter adapter = connection.GetDataAdapter(strSelect, true, true, true);
try
{
adapter.Update(dataTable);
}
catch (DBConcurrencyException exception)
{
LoggingService.Error("数据可能被其他人修改了,不能保存...");
throw exception;
}
}
}
connection.CommitTransaction();
try
{
if (!string.IsNullOrEmpty(str))
{
if (LoggingService.IsDebugEnabled)
{
LoggingService.DebugFormatted("将执行级联SQL:{0}", new object[] { str });
}
connection.ExecuteSql(str);
}
}
catch (Exception exception2)
{
LoggingService.ErrorFormatted("执行级联更新语句:{0},发生错语:{1}\r\n{2}", new object[] { str, exception2.Message, exception2.StackTrace });
}
}
catch (Exception exception3)
{
connection.RollBackTransaction();
throw exception3;
}
finally
{
connection.Close();
}
}
示例3: SaveAs
private void SaveAs(SMDataSource smDataSource, DataSet ds)
{
DBConnection connection = new DBConnection(smDataSource);
using (smDataSource.CreateConnection())
{
foreach (DataTable table in ds.Tables)
{
string strSelect = table.ExtendedProperties["selectsql"].ToString().ToLower();
string sql = "delete" + strSelect.Substring(strSelect.IndexOf(" from "));
if (sql.IndexOf(" where ") > 0)
{
LoggingService.DebugFormatted("将行删除语句:{0}", new object[] { sql });
int num = connection.ExecuteNonQuery(sql);
LoggingService.DebugFormatted("共删除了{0}行数据", new object[] { num });
}
DbDataAdapter adapter = connection.GetDataAdapter(strSelect, true, true, true);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
LoggingService.InfoFormatted("将异步另存{0}行数据...", new object[] { table.Rows.Count });
if (dataTable.Rows.Count == 0)
{
foreach (DataRow row in table.Rows)
{
DataRow row2 = dataTable.NewRow();
row2.ItemArray = row.ItemArray;
dataTable.Rows.Add(row2);
}
adapter.Update(dataTable);
}
else
{
LoggingService.WarnFormatted("另存数据前没有删除原来的{0}行数据,请检查", new object[] { dataTable.Rows.Count });
}
}
if (ds.ExtendedProperties.ContainsKey("CascadeSql"))
{
string str3 = (string) ds.ExtendedProperties["CascadeSql"];
if (!string.IsNullOrEmpty(str3))
{
try
{
connection.ExecuteNonQuery(str3);
}
catch (Exception exception)
{
LoggingService.Error(exception, "执行级联更新:{0}时出错", new object[] { str3 });
}
}
}
}
}