Last active
December 1, 2016 16:39
-
-
Save perfectly-panda/e41a3da38f55d8ebc047cd1b953c0ad3 to your computer and use it in GitHub Desktop.
Insert into a DB using a USQL outputter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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