I m 寻找最简单的途径,将Xml文档作为使用C#的储存程序参数。 实际上,我需要建立一个Xml文档,以便把这一xml储存在地库数据库中。 在数据库储存程序中,其参数为xml。 我已经建立了一个Xml文件,称斜体为 be。
StringWriter stringWriter = null;
XmlTextWriter writer = null;
try
{
stringWriter = new StringWriter(new StringBuilder());
writer = new XmlTextWriter(stringWriter);
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();
writer.WriteComment("Holiday Info");
writer.WriteStartElement("holidayInfo", "");
for (int groupIndex = 0; groupIndex < numberOfGroup; groupIndex++)
{
for (int religionIndex = 0; religionIndex < numberOfReligion; religionIndex++)
{
for (int jobStationIndex = 0; jobStationIndex < numberOfJobStation; jobStationIndex++)
{
writer.WriteStartElement("HOLIDAY", "");
writer.WriteAttributeString("intGroupID", chkGroupList.Items[groupIndex].Value.ToString());
writer.WriteAttributeString("intJobTypeId", "0");
writer.WriteAttributeString("intJobStationID", chkReligionList.Items[religionIndex].Value.ToString());
writer.WriteAttributeString("intHolidayID", ddlHolidayName.SelectedValue.ToString());
writer.WriteAttributeString("dtePermitedDate", DateTime.Now.ToShortDateString());
writer.WriteAttributeString("intReligionId", chkReligionList.Items[religionIndex].Value.ToString());
writer.WriteAttributeString("dteFromDate", txtFromDate.Text);
writer.WriteAttributeString("dteToDate", txtToDate.Text);
writer.WriteEndElement();
}
}
}
stringWriter.GetStringBuilder().ToString();
return will be what if i want to sent this file to the store procedure parameter?;
}
finally
{
if (writer != null) writer.Close();
if (stringWriter != null) stringWriter.Close();
}
如果想将这一档案作为xml参数送交储存程序,回归类型将是什么?
这是我的储存程序。
CREATE PROCEDURE [dbo].[sprHoliday_InsertHolidaysGroupPermission]
@intUserID INT =NULL,
@xmlHolidayPermissionDetails XML,
@insertStatus AS VARCHAR(200) OUT
AS
BEGIN
DECLARE @intEmployeeID int
IF (@intUserID IS NOT NULL)
BEGIN
SELECT @intEmployeeID = intEmployeeID From dbo.tblUserInfo WHERE tblUserInfo.intUserID = @intUserID
END
BEGIN TRANSACTION
BEGIN TRY
INSERT INTO dbo.tblEmployeeGroupPermissionHolidays
(intGroupID,
intJobTypeId,
intJobStationID,
intHolidayID,
dtePermitedDate,
intReligionId,
dteFromDate,
dteToDate)
(SELECT xmlHolidayPermissionDetails.item.value( @intGroupID[1] , INT ),
xmlHolidayPermissionDetails.item.value( @intJobTypeId[1] , INT ),
xmlHolidayPermissionDetails.item.value( @intJobStationID[1] , INT ),
xmlHolidayPermissionDetails.item.value( @intHolidayID[1] , INT ),
xmlHolidayPermissionDetails.item.value( @dtePermitedDate[1] , DATE ),
xmlHolidayPermissionDetails.item.value( @intReligionId[1] , INT ),
xmlHolidayPermissionDetails.item.value( @dteFromDate[1] , DATE ),
xmlHolidayPermissionDetails.item.value( @dteToDate[1] , DATE )
FROM @xmlHolidayPermissionDetails.nodes( //HOLIDAY ) AS xmlHolidayPermissionDetails(item)
)
COMMIT
INSERT INTO dbo.tblHRDataHistory values( Insert , Holiday Permission Data Insert , tblEmployeeGroupPermissionHolidays ,GETDATE(),@intEmployeeID)
SET @insertStatus = Holiday Permission has been iserted succesfully
END TRY
BEGIN CATCH
Rollback
SELECT @insertStatus = There was an error! + ERROR_MESSAGE()
END CATCH
END