How Do I Load SQL Server XML Datatype Into XmlDocument In C#
Feb 22, 2007
Hi there,
How do i load a XML document saved in SQL server as a XML data type into
XmlDocument xdoc = new XmlDocument();
xdoc.Load(// INTO HERE );
I can load a xml file saved to disk but haven't figured out how to retrive from a recordset. I have tried the following:
XmlDocument xdoc = new XmlDocument();
xdoc.Load(GetXmlFile(pnrID).ToString());
public string GetXmlFile(int pnrID){
SqlConnection cnn = null;
SqlCommand cmd = null;
string XML = "";
try {
cnn = new SqlConnection();
cnn.ConnectionString = "Server=;Initial Catalog=;UID=;PWD=;";
cnn.Open();
string selectQry = "SELECT [XML] FROM [TEMP_PNR] WHERE PnrID = @PnrID";
cmd = new SqlCommand(selectQry, cnn);
cmd.Parameters.AddWithValue("@pnrID", pnrID);
SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.Read())
XML = rdr.GetSqlXml(0).ToString();
}
catch (Exception ex)
{
throw ex;
}
finally {
cmd.Dispose();
cnn.Close();
}
return XML;
}
But this genereates the following error: Could not find file 'C:Program FilesMicrosoft Visual Studio 8Common7IDESystem.Data.SqlTypes.SqlXml'.
Any idea how i can achive this?
View 5 Replies
ADVERTISEMENT
Oct 23, 2006
Hi, I have xmldocument type that stores xml data. I would like to able to store that data in sql server 2005 as a xml data type. How can I accomplish this using ado sqlcommand? XmlDocument xdoc = new XmlDocument();SqlConnection conn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Test"].ConnectionString);conn.Open();SqlCommand cmd = new SqlCommand(); cmd.Connection = conn;cmd.CommandType = CommandType.StoredProcedure;cmd.CommandText = "spStoreApp";cmd.Parameters.AddWithValue("@PersId", "222-22-2222");cmd.Parameters.AddWithValue("@AppData", xdoc);try{cmd.ExecuteNonQuery();Response.Write("Storage of application successful");}catch (SqlException sqlx){Response.Write(sqlx.Message);}conn.Close();thanks in advance.
View 3 Replies
View Related
Sep 9, 2006
I have been fighting with this all day. If you can point me in the right direction I'd appreiciate it. I need to load about 500 jpg files into a table. The table has 3 columns an "ID", "Filename" which has the filename of the jpg in it already, but not the unc path, and a ("Photo" Image Datatype)column which is not populated yet. I need to store the Image file in the photo field so that I can run reports in reporting services and so on and so forth. I am not sure how to complete this task.
View 3 Replies
View Related
Jun 6, 2007
OK I am working on a SSIS package and am using a script task. I have to get remote xmldocuments from a server. Sounds simple enough. In C# it was easy but for some reason vb.net will not let me do this:
I can do a httpwebrequest and get the xml string into a variable strResponse
But the following will not work. The XmlDocument doesn't exists in the script task the vb code. On a side note I am importing Imports System.Xml in case anyone asks.
Dim doc As New XmlDocument
doc.LoadXml(strResponse)
Could anyone tell me how I would parse the xml elements using a script task?
here is the full code I am working with but all of the xml stuff has that blue squggly line underneathit.
Private Function ParseXmlIntoList(ByVal strResponse As String, ByVal l As List(Of StockInfo)) As List(Of StockInfo)
Dim doc As New XmlDocument
Try
doc.LoadXml(strResponse)
Catch
isError = True
Return l
End Try
Dim root As XmlElement = doc.DocumentElement
Dim list As XmlNodeList = root.SelectNodes("/StockData/Stock")
Dim x As Integer = 0
Dim n As XmlNode
For Each n In list
If l((x + intStartCount)).Symbol = getXMLElement(n, "Symbol") Then
l((x + intStartCount)).Price = Convert.ToDecimal(getXMLElement(n, "Last"))
l((x + intStartCount)).CompanyName = getXMLElement(n, "Name")
x += 1
Else
isError = True
Return l
End If
Next n
intStartCount = intStartCount + 25
Return l
End Function
Any help would be greatly appreciated.
Thanks,
JBelthoff
• Hosts Station is a Professional Asp Hosting Provider
• Position SEO can provide your company with SEO Services at an affordable price
› As far as myself... I do this for fun!
View 1 Replies
View Related
May 27, 2006
I would like to return an xmldocument from a 2005 vb clr stored procedure.
This is my definition for the stored procedure. passing in a string, return xmldoc.
Can I not return an xmldoc as output? The solution will build, but not run.
Partial Public Class StoredProcedures
<Microsoft.SqlServer.Server.SqlProcedure()> _
Public Sub SP_Transform(ByVal cc As String, <Out()> ByVal RetValue As XmlDocument)
Error 1 Column, parameter, or variable #2: Cannot find data type XmlDocument. SqlServerProject1
View 1 Replies
View Related
Aug 10, 2007
This is all I have in SSIS Script Task
Imports System.Xml
Public Sub Main()
Dim doc As XmlDocument
doc.Load("C:Data est.xml")
Dts.TaskResult = Dts.Results.Success
End Sub
I get this error
Object reference not set to an instance of an object.
Any idea - Ashok
View 4 Replies
View Related
May 25, 2006
The test sub below operates on a SQL Server Table with an xml-type field ("xml"). The purpose of the sub is to learn about storing and retrieving a whole xml document as a single field in a SQL Server table row.When the code saves to the xml field, it somehow automagically strips the xml.document.declaration (<?xml...>). So when it reads the xml field back and tries to create an xmldocument from it, it halts at the xmldocument.load.I order to get the save/retrieve from the xmlfield to work, I add the <?xml declaration to the string when I read it back in from the xml field (this is in the code below).At that point the quickwatch on the string I'm attempting to load into the xmldocument is this:-----------------------------------------------------<?xml version="1.0" encoding="utf-16" ?><Control type="TypeA"><Value1><SubVal1A>Units</SubVal1A><SubVal1Btype="TypeA">Type</SubVal1B></Value1><Value2><SubVal2A>Over</SubVal2A><SubVal2B>Load</SubVal2B></Value2></Control>-----------------------------------------------------The original xml document string is this:-----------------------------------------------------<?xml version="1.0" encoding="utf-16" ?><Control type="TypeA"> <Value1> <SubVal1A>Units</SubVal1A> <SubVal1B type="TypeA">Type</SubVal1B> </Value1> <Value2> <SubVal2A>Over</SubVal2A> <SubVal2B>Load</SubVal2B> </Value2></Control>-----------------------------------------------------which seems to have all the same characters as the quickwatch result above, but clearly is formatted differently because of the indenting.THE FIRST QUESTION: Is there a simpler way to do this whole thing using more appropriate methods that don't require adding the xml.document.declaration back in after reading the .xml field, or don't require using the memorystream to convert the .xml field in order to load it back to the XML document.THE SECOND QUESTION: Why does the original document open in the browser with "utf-16", but when I write the second document back to disk with "utf-16" it won't open...I have to change it to "utf-8" to open the second document in the browser.Here's the test sub'============================================ Public Sub XMLDSTest() '=========================================== Dim ColumnType As String = "XML" '=========================================== '----------Set up dataset, datatable, xmldocument Dim wrkDS As New DSet1() Dim wrkTable As New DSet1.Table1DataTable Dim wrkAdapter As New DSet1TableAdapters.Table1TableAdapter Dim wrkXDoc As New XmlDocument wrkXDoc.Load(SitePath & "App_XML" & "XMLFile.xml") Dim str1 = wrkXDoc.OuterXml Dim wrkRow As DSet1.Table1Row wrkRow = wrkTable.NewRow '=======WRITE to SQL Server============== '------ build new row With wrkRow Dim wrkG As Guid = System.Guid.NewGuid TestKey = wrkG.ToString .RecordKey = TestKey .xml = wrkXDoc.OuterXml '<<< maps to SQL Server xml-type field End With '----- add row to table and update to disk wrkTable.Rows.Add(wrkRow) wrkAdapter.Update(wrkTable) wrkTable.AcceptChanges() '----- clear table wrkTable.Clear() '=======READ From SQL Server ============== '----refill table, read row, wrkAdapter.FillBy(wrkTable, TestKey) Dim wrkRow2 As DSet1.Table1Row = _ wrkTable.Select("RecordKey = '" & TestKey & "'")(0) '===== WRITE TO New .xml FILE =========================== Dim wrkS1 As New StringBuilder Select Case ColumnType Case "XML" '---if xml build xml declaration: '---add this to xml from sql table => <?xml version="1.0" encoding="utf-16" ?> wrkS1.Append("<?xml version=" & Chr(34) & "1.0" & Chr(34)) wrkS1.Append(" encoding=" & Chr(34) & "utf-16" & Chr(34) & " ?>") wrkS1.Append(wrkRow2.xml) End Select Dim wrkBytes As Byte() = (New UnicodeEncoding).GetBytes(wrkS1.ToString) Dim wrkXDoc2 As New XmlDocument Dim wrkStream As New MemoryStream(wrkBytes) wrkXDoc2.Load(wrkStream) '=========================================== '---- this just shows that the file actually was touched Dim wrkN2 As XmlNode = wrkXDoc2.CreateNode(XmlNodeType.Text, "ss", "TestNode2") wrkN2 = wrkXDoc2.SelectSingleNode("//Value1/SubVal1B") wrkN2.Attributes("type").Value = "This was from the xml field" '---------------- '------ update the encoding....otherwise the file won't open in the browser with utf-16 Dim wrkN1 As XmlNode = wrkXDoc2.CreateNode(XmlNodeType.Element, "ss", "TestNode") wrkN1 = wrkXDoc2.FirstChild wrkN1.InnerText = Replace(wrkN1.InnerText, "utf-16", "utf-8") '------------Now write the file back as an .xml file Dim wrkFilePath As String = SitePath & "App_XML" & "XMLFile2.xml" Dim wrkXW As XmlWriter = XmlWriter.Create(wrkFilePath) wrkXDoc2.WriteContentTo(wrkXW) wrkXW.Close() End Sub===============================
View 8 Replies
View Related
Jan 28, 2015
Need to know if the varchar datatype field will ingore leading zeros when compared with numeric datatype ?
create table #temp
(
code varchar(4) null,
id int not null
)
insert into #temp
[Code] .....
View 4 Replies
View Related
Apr 24, 2008
Good afternoon,
I have an issue with an ssis variable datatype.
The scenario is as follows:
I have a stored procedure:
PROCEDURE [dbo].[sp_newTransaction]
@sourceSystem varchar(50),
@txOut NUMERIC(18,0) OUTPUT
AS
insert into scn_transaction (sourceSystemName) values(@sourceSystem);
SELECT @txOut = @@identity
Whose purpose is to perform an insert into a table and return me the identity value of the inserted record, which I'll then use throughout the rest of my package. The identity column in the inserted table is numeric(18,0).
I execute the stored proc with the following sql with an OLE DB connection manager:
exec sp_newTransaction ?, ?
The first parameter is a string variable from earlier in the package, and the second is the output parameter. I have the following parameter mappings to the execute sql task:
User:ystxId output numeric 1 -1
User:ourceSys input varchar 0 -1
The proc is correctly called, and the row insesrted, however I get a type conversion error when SSIS attempts to map the return parameter to my package variable... I've tried all sorts of combonations, and can't seem to get it to execute.
At one point I wasn't returning a numeric, but rather an int from the stored proc, and all was well until I went to use the variable in a derived column later in the package, and the type was converted quite incorrectly (a 1 was 77799789080 or some such), indicating a type conversion error likely related to the encoding of the number.
I'd like to keep the datatypes as numeric and make ssis use those - any pointers are greatly appreciated as to what type my package variable should be to allow proper assignment of a sql server numeric type to it.
Thanks much,
B
View 6 Replies
View Related
Sep 17, 2003
Database is SQL Server 2000
I have a field in a table that stores date of birth. The field's datatype is char(6) and looks like this: 091703 (mmddyy). I want to convert this value to a datetime datatype.
What is the syntax to convert char(6) to datetime?
Thank you in advance.
View 1 Replies
View Related
Mar 14, 2008
Hi,
I imported a table from Accees to SQL 7 with data in it.
I need to modify one of the datatype columns to "datetime" from nvarchar.
I tried to convert it manually, in SQL Server Enterprise Manager tool, but it gave me an error.
I also tried, creating another column "DATE2-datatype:datetime" and updating the column with the old one.
UPDATE users SET DATE2 = DATE.. But it also faild,..
How can I modify the column?
Thank you.
View 10 Replies
View Related
Dec 14, 2007
Hi,
Here I will describe my problem.
1. We are loading large amount of data from database on background thread which is starting on Application_start event in global.aspx.cs file.The data is later cached for subsquent request to improve the performance.
2. Now when we put the application on web farm garden, it is not able to load the application.
3. We are sending the request the servers through Router kind of application.
4 This application is working fine on single server enviornment.
Please help us.
Ajay Kumar Dwivedi
View 1 Replies
View Related
Apr 27, 2007
I just have done the SSIS example in the tutorial document included when install SQL 2005 ENT. I have a problem that whenever I test to run, the service load all data from source with out noticing about the data (I mean it load all the data to the destination), I do it several time and it continue to load all without checking. That mean the data is dublicated when the schedule run???
I think there should be a paramete or something like that to help the engine just load the new data to the destination. Could you help please?
Thank
View 3 Replies
View Related
Dec 15, 2005
HI,I have a table with IDENTITY column with the datatype as INTEGER. Nowthis table record count is almost reaching its limt. that is totalrecord count is almost near to 2^31-1. It will reach the limit with inanother one or two months.In order to avoid the arithmentic overflow error 8115, we would likechange the datatype from INT to BIGINT. we hope this will solve ourproblem.How do I approch this datatype conversion?. Since the data count ishuge, that leads to a long down time of database.we need better approach or solution for this problem?. kindly give mea better solution that will reduce the total downtime of the productiondatabase.?.Regards
View 1 Replies
View Related
Feb 25, 2008
Hi guys..
i have so doubts in my mind and that i want to discuss with you guys... Can i use more then 5/6 fields in a table with datatype of Text as u know Text can store maximu data... ? acutally i am trying to store a very long strings values into the all fields. it's just popup into my mind that might be table structer would not able to store that my amount of data when u use more then 5/6 text datatypes...
and another thing... is which one is better to use as data type "Text" or "varchar(max)"... ?
if any article to read more about these thing,, can you refere to me...
Thanks and looking forward.-MALIK
View 5 Replies
View Related
Mar 10, 2006
I have a access table that I need to create in SQL Server, there are field with yes/no, in sql server what datatype would I use?
Thanks
View 2 Replies
View Related
Sep 21, 2007
hi guys,
is it possible to do a enum datatype in SQL Server? if so can anyone point me to an example please?
thanks,
benny
View 3 Replies
View Related
Nov 4, 2005
Is there a way to create a datatype other than varchar that is greater than 8000? :o
View 3 Replies
View Related
May 13, 2005
Hi,
I've just created an ecommerce website using ASP and SQL Server 2000 - on my development machine (WinXP Pro, IIS, SQL Server 2000) the SQL Server datatype for the price field is Money - however, the datatype on my hosts SQL Server is Currency (there is no Money datatype available??)
Now, the problem is this: on my local machine I enter a price of say 99.99 - this shows up on the front-end & in the admin area as 99.99, no problem. Now, on the live server when I enter 99.99 it is somehow converted to 9999 - if I enter 99,99 (with a comma) it shows correctly as 99.99 - however, when I go to edit the price it reverts to 9999...does anyone know what is going on here? Why is it converting 99.99 to 9999??
Please let me know if you need more clarification of the above.
Many thanks,
Peter
__________________
Paliz Design
http://www.palizdesign.com/
View 4 Replies
View Related
Sep 23, 2004
Dear All,
I just want to know ,wheather there is any way to store 'hyperlink' in sql Table as in Ms Access.
or
What is the Procedure to store a Path of a file in SQL table and file should be able to retrieve through the query.
Thhank you
Graceson Mathew
View 1 Replies
View Related
Feb 4, 2015
I need to load the latest csv files from file server , The files are placed in a folder called -
Posted 02022015- --> csv files .
I am able to copy the csv files from filserver using bulk insert (manually) , giving the file location
I am having difficulty picking up the latest folder which is posted on the server and import it into database using a stored proc .
View 2 Replies
View Related
Jun 11, 2008
What is the best datatype in SQL Server 2000 to use for a US dollar amount?
View 1 Replies
View Related
Jan 16, 2005
Does boolean data type exists in Sequel if y how??? if N y???
How can i opt for boolean ( nearest ) ?
I've used Bit with not null
i want 2 display column of bit datatype into Checkbox .. Is is possible??
Whenver i bind the datatype of bit for checkbox it is throwing an error??
HELP ME HELP ME
View 1 Replies
View Related
Apr 30, 1999
Can anyone tell me how to calculate datatype conversion times in SQL Server
7? I have a varchar (15) field that I tried to convert to integer using
the table design GUI in Enterprise Manager. The table holds about
72,000,000 records about 1k apiece in size.
It's been running for about an hour now with no seeable results. In
Performance Monitor I don't see any page reads happening, so is this
indicative that the process died? Enterprise Manager is no longer
responsive - even if I open another session.
I'd like to know how long I can reasonably expect this conversion to take.
Also, how can I abort this request safely if I want to?
Thanks for any insights.
Alex Nguyen
View 1 Replies
View Related
Jan 17, 2003
Anybody has datatype list for sqlserver matching Oracle datatype
Thanks,
Ravi
View 1 Replies
View Related
Aug 30, 2006
What is the max. number of characters in ntext?
Are there any way we can format the output of ntext? Or it will just come out as one long line?
Thanks.
View 1 Replies
View Related
Apr 25, 2007
Hi
I am populating a rad grid with foreign language data. I have set the sql server 2005 Database table column to nvarchar. This works for all the languages except Hindi and Punjabi resulting in the text appearing as letters instead of the correct symbols. Can anyone tell me the correct sql server column datatype for Hindi and Punjabi characters?
Thanks
View 1 Replies
View Related
Dec 25, 2005
Which sql-server datatype corresponds to the "single" of .NET ?
Thank you very much for any help!
Regards,
Fabian
my favorit hoster is ASPnix : www.aspnix.com !
View 4 Replies
View Related
Sep 11, 2007
Hi folks,
We have a nice issue here. We are running SQL 2005 Dev edition Service Pack 2 and we are trying to copy the contents of one table in a local sql server database to another table in another database on the same local sql server. We use an oledb source and a sql server destination. The table structure is exactly the same. One column is of the datatype ntext, when we try to load the contents the package will stop with the error:
OnError 11-9-2007 14:38:24 11-9-2007 14:38:24 00:00:00 The attempt to send a row to SQL Server failed with error code 0x80004005.
OnError 11-9-2007 14:38:24 11-9-2007 14:38:24 00:00:00 SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "<TABLE>" (3382) failed with error code 0xC02020C7. The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.
OnError 11-9-2007 14:38:24 11-9-2007 14:38:24 00:00:00 SSIS Error Code DTS_E_THREADFAILED. Thread "WorkThread0" has exited with error code 0xC02020C7. There may be error messages posted before this with more information on why the thread has exited.
OnError 11-9-2007 14:38:26 11-9-2007 14:38:26 00:00:00 SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E07.
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E07 Description: "Error converting data type DBTYPE_DBTIMESTAMP to datetime.".
OnError 11-9-2007 14:38:26 11-9-2007 14:38:26 00:00:00 A commit failed.
Removing the column from the sql server destination will result in loading the complete table. Using an oledb destination instead of sql server destination fixes the problem. Is this a bug in the SQL server destination component?
Thanks,
Marc
View 4 Replies
View Related
May 28, 2008
Hi,
i wanted to read some datasets from a table with the ROWVERSION. Then i wanted to save these records with the ROWVERION- Column in a temp table. Now it seems i cant explicitely write data in a ROWVERSION Column. As i understand its only possible to write a default value in such columns. Only SQL Server itself can write into ROWVERSION columns.
Am i right with this meaning?
Thx in advance...
Greets Kamei
View 4 Replies
View Related
Mar 25, 2008
Hi,
How can i install Report server on a load balanced server.. My sql server is on a different machine and we have 2 webservers where we need to install Reporting services. Any help will be appreciated.
Thank you,
Karen
View 6 Replies
View Related
Mar 16, 2001
Please help. We have no idea what is wrong.
Error message occurs at the end of the load.
"Error at Destination for Row number 6218607. Errors encountered so far in this task: 1. SqlDumpExecptionHandler: Preocess 11 generated fatal exception c0000005 EXCEPTION_ACCESS_VIOLATION. SQL Server is terminating this process."
Thanks for your help
Adrian.
View 1 Replies
View Related
Jul 20, 2000
Is it possible to take a backup of a database and load it to another server?
I know the users id will be messed up. But, I don't want to do a detach
or a DTS task. I just want to verify that the backup is good.
thanks
View 1 Replies
View Related