Skip to content

Instantly share code, notes, and snippets.

@perfectly-panda
Last active December 1, 2016 16:39
Show Gist options
  • Save perfectly-panda/e41a3da38f55d8ebc047cd1b953c0ad3 to your computer and use it in GitHub Desktop.
Save perfectly-panda/e41a3da38f55d8ebc047cd1b953c0ad3 to your computer and use it in GitHub Desktop.
Insert into a DB using a USQL outputter
[SqlUserDefinedOutputter]
public class ExternalDatabase : IOutputter
{
private static string ConnectionString = "YOUR CONNECTION STRING";
public override void Output(IRow row, IUnstructuredWriter output)
{
using (System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection(ConnectionString))
{
sqlConnection1.Open();
var sql = @"INSERT (column_name) INTO [dbo].[table] VALUES (" + row.Get<string>("column_name")+ ")";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = sql;
cmd.Connection = sqlConnection1;
cmd.ExecuteNonQuery();
sqlConnection1.Close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment