c# - having trouble uploading datatable to SqlServer 2008 from Winforms application -


i'm streaming data csv file , trying import sql server 2008. i've looked around on web , i've come approach , not working. ideas on how make better (in sense works).

the input parameter csv data in datatable.

here's code:

   private void exportcsv(datatable dtcsv)      {         datetime dayofyear = datetime.now.date;         dtcsv.tablename = "activationdate_"+dayofyear.tostring();         string createtemptable = "select * thisactivation @tvp";         using (sqldataadapter adap = new sqldataadapter(createtemptable,getconnection()))         {             adap.insertcommand.parameters.add("@tvp", sqldbtype.nvarchar, int.maxvalue);             adap.insertcommand.parameters["@tvp"].value = dtcsv;             adap.insertcommand.executenonquery();         }     } 

you can't parameterize table names (or column names, matter).

one option revert dynamic sql, though opens sql injection.

this work, though should careful validate dtcsv avoid sql injection.

string createtemptable = "select * thisactivation " + dtcsv; 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -