Retrieve xml elements from sql server - c#

I have xml stored in a sqlserver table column type as varchar. I need few elements from that xml string. Is there a way I can process this xml and store its elements in a table and retrieve when ever I need.

Related

How make Insert Into table SQL from DataSet

I have json which the converted to Dataset. And this data I wanna written to table in SQl. But I don't know how this doing. I did tried doing through SqlBulkCopy but me this don't likes because that needed create other table. And data always different.Thanks.

How can I insert master/detail records into SQL server using parameterized stored procedure with XML detail records as one of the params

I want to create a C# method that calls a parameterized SQL Server stored procedure. The parameters I am passing are;
*int ServiceActionType
*string FilePath
*string ServiceName
*string ApplicationServerName
*XmlDocument ListOfPieceIDs
In the stored procedure, I first want to create the master record, in the ServiceActions table, consisting of the ServiceActionType, FilePath, ServiceName, ApplicationServerName, PieceCount (which would be the count of the elements in the XML document) and the ActionDateTime (the current date and time)
I want to save the master record and get it's Identity value to use in the next step.
Then I want to iterate through the XML document and insert new records in the ServiceActionsPieceIDs table, one record for each XML element, with each record having the following fields;
*ServiceActionID (the Identity value from the newly inserted ServiceActions record)
*PieceID (The PieceID value from the current iteration through the XML document)
I believe I have the C# method created properly but I am having trouble figuring out the T-SQL stored procedure code to insert the ServiceAction master record, get the Identity field from the ServiceAction master record insert and then iterate through the XML document to extract the PieceID element value from each element set to insert the ServiceActionPieceIDs detail records.
Thanks,
Dave

How do I display XML data in SQL in HTML

I am working on redesigning an old application that stored content in sql as xml data. I know that if I have a file I can use this to display the data in HTML:
xmlhttp.open("GET","xmlfile.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
Now, lets say I have a table in SQL. In a column I have the contents of "xmlfile.xml". How can I go about displaying that data?
Are you looking for specific field in the xml, SQL Server can query fields of a xml tag inside a sql server column row.
http://msdn.microsoft.com/en-us/library/ms345122(v=sql.90).aspx

Store DataTable to SQL Server column

I'm trying to store a DataTable into a single column in a SQL Server table. The idea behind this is a user runs a SQL command and the returned output is stored into a datatable, then I want that datatable to be stored into a SQL Server logging table. Later on I want to be able to retrieve that entire datatable back for displaying on a logging aspx page.
Currently I'm just storing it as a big string but that doesn't give me column headers and the formatting is kinda funky as well as being inefficient.
TIA
I would probably convert the datatable to XML and store it into an XML field type if I was going to do what you are trying to do.
Hello you can try with WriteXml
this link give you sample interessant : http://msdn.microsoft.com/fr-fr/library/system.data.datatable.writexml.aspx
Another Idea is to create two tables in your database. It is slightly complex.
One Table contains two columns, Let name the table PTable.
Columns:
ID and ColumnID
ID is the primary key and ColumnID contains the name of your column in datatable
After creating this table create another table. It will consists of three fields. Let name it STable. This table stores the columns of you datatable.
Columns:
stblID, PtblID and PtColumnID
StbID is the primary key in this table, PtblID is the Primary key of PTable and PtColumnID is the ColumnID of PTable. This table stores the rows of table. Now store the data in this table and receive the data when you need it.
and the simplest idea is to create a table in your datbabase having an xml column and store your datatable as an xml.

how to handel XML datatype in Datatable while inserting Data through SqlBulkCopy for sql server?

In my application i want to insert XML document in to my table which has a column with XML datatype. Now issue comes when i use SqlBulkCopy in my application. i have to pass a Datatable to SqlBulkCopy.WriteToServer method. it is showing me InvalidCastException. for storing XML data in datatable, I tried to utilize Datatype property of DataColumn and set it to XmlReader (didn't worked), XElement (didn't worked) and string which is showing InvalidCastException.
So I want to know which datatype should i specify for DataColumn so that data can be inserted using sqlbulkcopy.
Thanks,
Try sending the xml as string type

Categories

Resources