I have a table with the column's datatype as xml in SQL Server 2005. I created a stored procedure to insert values into that column.
But when calling the SP from code in C#, its giving me an error
Failed to convert parameter value from a XDocument to a String.
Can anyone help with this?
This is the stored procedure I created:
Create Procedure [dbo].[TestReportRepository_Save]
@ReportExecutionTime datetime,
@ReportFile xml,
as
begin
insert into TestReportRepository(ReportExecutionTime,ReportFile) values(@ReportExecutionTime,@ReportFile)
end
The C# code is
DbParameter dbParam1 = dac.Parameter("@ReportExecutionTime", ReportExecutionTime, DbType.DateTime, ParameterDirection.Input);
DbParameter dbParam2 = dac.Parameter("@ReportFile", xmlDoc.Document, DbType.Xml, ParameterDirection.Input);
DbParameter[] dbParamColl = new DbParameter[] { dbParam1, dbParam2 };
long reportID = dac.Save("TestReportRepository_save", dbParamColl);
Please help me identify what I am doing wrong.
{ }) on the editor toolbar to nicely format and syntax highlight it!XDocumentdirectly - you'll have to "serialize" thatXDocumentinto a string to pass it to SQL Server (e.g. usign the.ToString()method)