c# - Adding XML to a table in Microsoft SQL Server -


  • i want table called testpack 3 coulmns - name, testcase number, testplan
  • testplan xml file stored in c drive of computer
  • how can go creating table? note: want entire file added instead of writing actual xml code in 3rd column.

also, new asp.net, c# , microsoft sql server, spare dumb questions

first need create table following this

create table [mytable] ( id int, [myxmlcolumn] xml); 

and need insert data using sqlparameter

 public static void insertxmldataintotablebysqlparameter()     {         using (sqlconnection sqlconnection = new sqlconnection(@"data source=.\sqlexpress;      initial catalog=morgandb; integrated security=sspi;"))         {             sqlconnection.open();              // create table if not exists              string createtablequery = @"create table [mytable] ( id int, [myxmlcolumn] xml)";             sqlcommand command = new sqlcommand(createtablequery, sqlconnection);             command.executenonquery();            //whateever xml data              string xmldata = "<xmlroot><childnode></childnode></xmlroot>";              string insertxmlquery = @"insert [mytable] (id,[myxmlcolumn]) values(1,@myxmlcolumn)";            // insert xml value sql table sqlparameter             sqlcommand insertcommand = new sqlcommand(insertxmlquery, sqlconnection);             sqlparameter sqlparam = insertcommand.parameters.addwithvalue("@myxmlcolumn", xmldata);             sqlparam.dbtype = dbtype.xml;             insertcommand.executenonquery();         }     } 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -