如何在数据库中插入XML数据 [英] How to insert XML data in databse

查看:84
本文介绍了如何在数据库中插入XML数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在db中创建了一个像这样的表



I created a table in db like this

CREATE TABLE [dbo].[XmlEmpTable](
 [ID] [int] IDENTITY(1,1) NOT NULL,
 [LoginId] [int] NULL,
 [FormName] [nvarchar](255) NULL,
 [XMLFile] [xml] NULL
 ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]





我的aspx页面中有3个文本框和1个单选按钮。

我想插入3个Textbox值int o xml格式的XMLFile列。

我如何实现这一目标?



任何人请帮忙。



提前谢谢



I have 3 textboxes and 1 radio button in my aspx page.
I want to insert 3 Textbox values into XMLFile column in xml format.
How can i achieve that?

Anybody please help.

Thanks in advance

推荐答案

你可以用你的C#代码来做 -

You can do it in your C# code like-
XElement xml = new XElement("Emp");
            xml.Add(
                new XElement("Field", 
                    new XAttribute("Name", "Field1"), 
                    textbox1.Text),
                 new XAttribute("Name", "Field2"), 
                    textbox2.Text),
                 new XAttribute("Name", "Field3"), 
                    textbox3.Text),
            );



现在为[XMLFile]字段传递xml的值。



希望,它有帮助:)


Now pass the value of "xml" for the [XMLFile] field.

Hope, it helps :)


这篇关于如何在数据库中插入XML数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆