本文整理汇总了C#中DbConnection.insert方法的典型用法代码示例。如果您正苦于以下问题:C# DbConnection.insert方法的具体用法?C# DbConnection.insert怎么用?C# DbConnection.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbConnection
的用法示例。
在下文中一共展示了DbConnection.insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoJob
public override void DoJob()
{
const string ID_COLUMN_NAME = "EmployeeID";
const string TABLE_NAME = "Employees";
StringBuilder sb = new StringBuilder();
sb.AppendFormat("JobType: {0}", GetName()).AppendLine();
/*
* TODO: Properly read in connection information here.
*/
DbConnectorInfo sourceInfo = new DbConnectorInfo("localhost\\SQLEXPRESS", "NORTHWND", "sa", "Conestoga1");
destinationInfo = new DbConnectorInfo("localhost\\SQLEXPRESS", "SimpleNorthwind", "sa", "Conestoga1");
DbConnection sourceConnection = new DbConnection(sourceInfo, "MS");
DbConnection destinationConnection = new DbConnection(destinationInfo, "MS");
/*
* Build the query for updating from the table.
*/
//List<string> columns_to_pull = new List<string>();
//columns_to_pull.Add(ROW_KEY);
//columns_to_pull.Add(ROW_NAME);
//columns_to_pull.Add(TABLE_NAME);
List<string> where_clauses = new List<string>();
/*
* Some janky stuff to get this working.
*/
where_clauses.Add(ID_COLUMN_NAME + " = " + i);
++i;
sb.Append("Connecting to source...").AppendLine();
sb.AppendFormat("DbConnectorInfo:").AppendLine();
sb.AppendFormat("server: {0}", sourceInfo.server).AppendLine();
sb.AppendFormat("database: {0}", sourceInfo.database).AppendLine();
sb.AppendFormat("userid: {0}", sourceInfo.userid).AppendLine();
sb.Append("Connecting to destination...").AppendLine();
sb.AppendFormat("DbConnectorInfo:").AppendLine();
sb.AppendFormat("server: {0}", destinationInfo.server).AppendLine();
sb.AppendFormat("database: {0}", destinationInfo.database).AppendLine();
sb.AppendFormat("userid: {0}", destinationInfo.userid).AppendLine();
/*
* Open the source and destination databases.
*/
if (!sourceConnection.ConnectionOpen)
{
sourceConnection.OpenDBConnection();
}
if (!destinationConnection.ConnectionOpen)
{
destinationConnection.OpenDBConnection();
}
/*
* Pull data from BioLinks.
* TODO: Figure out wtf this method even takes.
*/
DataTable sourceData = sourceConnection.pullData(TABLE_NAME, null, where_clauses);
sb.AppendLine("Source Data: ");
foreach (DataRow row in sourceData.Rows)
{
sb.AppendLine(sourceData.Rows.IndexOf(row).ToString());
}
/*
* Insert/Update pulled into BioTrack.
*/
destinationConnection.insert(TABLE_NAME, sourceData);
destinationConnection.insert(TABLE_NAME, sourceData);
Logger.logMessage(sb.ToString(), AppDomain.CurrentDomain.BaseDirectory + AppDomain.CurrentDomain.RelativeSearchPath + "\\Events.txt");
/*
* Close the source and destination databases.
*/
sourceConnection.CloseDBConnection();
destinationConnection.CloseDBConnection();
}