如何插入,更新,删除数据集中显示的xml值 [英] How to insert,update,delete the the xml values that presents in dataset

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

问题描述

海,

我有一个包含xml文件的应用程序.我将此xml文件转换为数据集.之后,我要插入,更新,删除数据集中的xml值.我该怎么做.下面我已发送了代码.Plz清除我的疑问.

///authors.xml///

Hai,

I have an application that contains xml file.I am converted this xml file into dataset.After that i want to insert,update,delete the xml values in the dataset.How can I do that one.Below I has send the code.Plz clear my doubt.

///authors.xml///

<authors_table>
  <authors>
    <au_id>172-32-1176</au_id>
    <au_lname>White</au_lname>
    <au_fname>Johnson</au_fname>
    <phone>408 496-7223</phone>
    <address>10932 Bigge Rd.</address>
    <city>Menlo Park</city>
    <state>CA</state>
    <zip>94025</zip>
    <contract>true</contract>
  </authors>
  <authors>
    <au_id>213-46-8915</au_id>
    <au_lname>Green</au_lname>
    <au_fname>Margie</au_fname>
    <phone>415 986-7020</phone>
    <address>309 63rd St. #411</address>
    <city>Oakland</city>
    <state>CA</state>
    <zip>94618</zip>
    <contract>true</contract>
  </authors>
  <authors>
    <au_id>238-95-7766</au_id>
    <au_lname>Carson</au_lname>
    <au_fname>Cheryl</au_fname>
    <phone>415 548-7723</phone>
    <address>589 Darwin Ln.</address>
    <city>Berkeley</city>
    <state>CA</state>
    <zip>94705</zip>
    <contract>true</contract>
  </authors>
  <authors>
    <au_id>267-41-2394</au_id>
    <au_lname>Hunter</au_lname>
    <au_fname>Anne</au_fname>
    <phone>408 286-2428</phone>
    <address>22 Cleveland Av. #14</address>
    <city>San Jose</city>
    <state>CA</state>
    <zip>95128</zip>
    <contract>true</contract>
  </authors>
  <authors>
    <au_id>274-80-9391</au_id>
    <au_lname>Straight</au_lname>
    <au_fname>Dean</au_fname>
    <phone>415 834-2919</phone>
    <address>5420 College Av.</address>
    <city>Oakland</city>
    <state>CA</state>
    <zip>94609</zip>
    <contract>true</contract>
  </authors>
</authors_table>



///xmltodatasetpageedit.aspx///



///xmltodatasetpageedit.aspx///

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="xmltodatasetpageedit.aspx.cs" Inherits="WebApplication4.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head  runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
          >
            <columns>
                <asp:CommandField HeaderText="Edit" ShowEditButton="True" />
                <asp:TemplateField HeaderText="au_id">
                    <edititemtemplate>
                        <asp:Label ID="Label1" runat="server" Text=''<%# Bind("au_id") %>''>
                    </edititemtemplate>
                    <itemtemplate>
                        <asp:Button ID="Button1" runat="server" Text=''<%# Bind("au_id") %>'' />
                    </itemtemplate>
                
                <asp:TemplateField HeaderText="au_lname">
                    <edititemtemplate>
                        <asp:Label ID="Label2" runat="server" Text=''<%# Bind("au_lname") %>''>
                    </edititemtemplate>
                    <itemtemplate>
                        <asp:Button ID="Button2" runat="server" Text=''<%# Bind("au_lname") %>'' />
                    </itemtemplate>
                
                <asp:TemplateField HeaderText="au_fname">
                    <edititemtemplate>
                        <asp:Label ID="Label3" runat="server" Text=''<%# Bind("au_fname") %>''>
                    </edititemtemplate>
                    <itemtemplate>
                        <asp:Button ID="Button3" runat="server" Text=''<%# Bind("au_fname") %>'' />
                    </itemtemplate>
                
                <asp:TemplateField HeaderText="phone">
                    <edititemtemplate>
                        <asp:Label ID="Label4" runat="server" Text=''<%# Bind("phone") %>''>
                    </edititemtemplate>
                    <itemtemplate>
                        <asp:Button ID="Button4" runat="server" Text=''<%# Bind("phone") %>'' />
                    </itemtemplate>
                
                <asp:TemplateField HeaderText="address">
                    <edititemtemplate>
                        <asp:Label ID="Label5" runat="server" Text=''<%# Bind("address") %>''>
                    </edititemtemplate>
                    <itemtemplate>
                        <asp:Button ID="Button5" runat="server" Text=''<%# Bind("address") %>'' />
                    </itemtemplate>
                
                <asp:TemplateField HeaderText="city">
                    <edititemtemplate>
                        <asp:Label ID="Label6" runat="server" Text=''<%# Bind("city") %>''>
                    </edititemtemplate>
                    <itemtemplate>
                        <asp:Button ID="Button6" runat="server" Text=''<%# Bind("city") %>'' />
                    </itemtemplate>
                
                <asp:TemplateField HeaderText="state">
                    <edititemtemplate>
                        <asp:Label ID="Label7" runat="server" Text=''<%# Bind("state") %>''>
                    </edititemtemplate>
                    <itemtemplate>
                        <asp:Button ID="Button7" runat="server" Text=''<%# Bind("state") %>'' />
                    </itemtemplate>
                
                <asp:TemplateField HeaderText="zip">
                    <edititemtemplate>
                        <asp:Label ID="Label8" runat="server" Text=''<%# Bind("zip") %>''>
                    </edititemtemplate>
                    <itemtemplate>
                        <asp:Button ID="Button8" runat="server" Text=''<%# Bind("zip") %>'' />
                    </itemtemplate>
                
                <asp:TemplateField HeaderText="contract">
                    <edititemtemplate>
                        <asp:Label ID="Label9" runat="server" Text=''<%# Bind("contract") %>''>
                    </edititemtemplate>
                    <itemtemplate>
                        <asp:Button ID="Button9" runat="server" Text=''<%# Bind("contract") %>'' />
                    </itemtemplate>
                
                <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />
            </columns>
        
    </div>
    <br />
    <br />
    <asp:Button ID="Button10" runat="server" onclick="Button10_Click" 
        style="height: 26px" Text="Button" />
    </form>
</body>
</html>

推荐答案

将数据集绑定到可绑定控件,最有可能是datagridview?此绑定控件在编辑模式下更新数据集中的数据.您可以具有单独的用户界面,以将新数据输入数据集.

基本上,这些XML元素根据xml的数据结构安排在表中.

现在使用数据集的WirteXml()方法写回xml
Bind the dataset to a bindable control, most probably datagridview?. This bound controls update the data in the dataset on edit mode. You can have a separate user interface to enter new data to the dataset.

Basically those XML elements are arranged into tables according to the data strructure of your xml.

Now write back the xml using the dataset''s WirteXml() method


您可以从
You could start with this[^] easy sample.


这篇关于如何插入,更新,删除数据集中显示的xml值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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