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
Post a Comment