简体   繁体   中英

dataset to XML not passing column values

I have a sqldatasource that shows in a grid view. So basically what I did was took the gridview and made it to a dataset to export to a XML file. The issue is the XML file is being created (when pressing the report button I have in the aspx page) with the columns in it but that values of the columns are not showing. Can anyone help me with this issue?

bellow is the XML file being generated when pressing the report button(Sample2.xml):

<?xml version="1.0" standalone="yes"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="DefaultView" msdata:CaseSensitive="False" msdata:Locale="en-US">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="USERID" type="xs:int" minOccurs="0" />
              <xs:element name="NAME" type="xs:string" minOccurs="0" />
              <xs:element name="TITLE" type="xs:string" minOccurs="0" />
              <xs:element name="CHECKTIME" type="xs:dateTime" minOccurs="0" />
              <xs:element name="CHECKTYPE" type="xs:string" minOccurs="0" />
              <xs:element name="trans" type="xs:int" minOccurs="0" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

the C# code for the aspx page:

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;



namespace TimeClockViewer
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {

        }

        protected void btnReport_Click(object sender, EventArgs e)
        {
            DataSourceSelectArguments args = new DataSourceSelectArguments();          
            DataView view = (DataView)SqlDataSource1.Select(args);
            DataTable table = view.ToTable();        
            DataSet ds = new DataSet();


            ds.Tables.Add(table);
            ds.WriteXmlSchema("Sample2.xml");

        }


    }
}

the aspx page code:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="TimeClockManager.aspx.cs" Inherits="TimeClockViewer.WebForm1" %>
<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet" ConnectionString="<%$ ConnectionStrings:attConnectionString %>" SelectCommand="SELECT USERINFO.USERID, USERINFO.NAME, USERINFO.TITLE, CHECKINOUT.CHECKTIME, CHECKINOUT.CHECKTYPE, CHECKINOUT.trans FROM USERINFO INNER JOIN CHECKINOUT ON USERINFO.USERID = CHECKINOUT.USERID WHERE (USERINFO.NAME = @NAME) AND (@NAME &lt;&gt; '-1') AND (CHECKINOUT.CHECKTIME BETWEEN @startDate AND @endDate + ' 23:59:00.000') OR (@NAME = '-1') AND (CHECKINOUT.CHECKTIME BETWEEN @startDate AND @endDate + ' 23:59:00.000') AND (1 = 1)" UpdateCommand="UPDATE CHECKINOUT SET CHECKTYPE = @CHECKTYPE, CHECKTIME = @CHECKTIME FROM CHECKINOUT INNER JOIN USERINFO ON CHECKINOUT.USERID = USERINFO.USERID WHERE (CHECKINOUT.trans = @trans) AND (CHECKINOUT.USERID = @USERID)">
        <SelectParameters>
            <asp:ControlParameter ControlID="ddlEmployee" Name="NAME" PropertyName="SelectedValue" />
            <asp:ControlParameter ControlID="txtBoxStartDate" Name="startDate" PropertyName="Text" />
            <asp:ControlParameter ControlID="txtBoxEndDate" Name="endDate" PropertyName="Text" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="CHECKTYPE" />
            <asp:Parameter Name="CHECKTIME" />
            <asp:Parameter Name="trans" />
            <asp:Parameter Name="USERID" />
        </UpdateParameters>
    </asp:SqlDataSource>
&nbsp;<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:attConnectionString %>" SelectCommand="SELECT [NAME] FROM [USERINFO] ORDER BY [NAME]"></asp:SqlDataSource>
    Employee:
    <asp:DropDownList ID="ddlEmployee" runat="server" DataSourceID="SqlDataSource2" DataTextField="NAME" DataValueField="NAME" Height="40px" Width="193px" AppendDataBoundItems="True">
        <asp:ListItem Value="-1">All</asp:ListItem>

    </asp:DropDownList>
&nbsp;&nbsp;&nbsp; Start Date:

    <asp:TextBox ID="txtBoxStartDate" runat="server" Width="146px"></asp:TextBox>

&nbsp;&nbsp;&nbsp; End Date<ajaxToolkit:CalendarExtender ID="txtBoxStartDate_CalendarExtender" runat="server" Enabled="True" TargetControlID="txtBoxStartDate">
    </ajaxToolkit:CalendarExtender>
    :
    <asp:TextBox ID="txtBoxEndDate" runat="server" Width="146px"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <ajaxToolkit:CalendarExtender ID="txtBoxEndDate_CalendarExtender" runat="server" Enabled="True" TargetControlID="txtBoxEndDate">
    </ajaxToolkit:CalendarExtender>
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
    <br />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:GridView ID="gvEmployee" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="USERID,trans" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
                <AlternatingRowStyle BackColor="White" />
                <Columns>
                    <asp:CommandField ShowEditButton="True" />
                    <asp:BoundField DataField="USERID" HeaderText="USERID" InsertVisible="False" ReadOnly="True" SortExpression="USERID" />
                    <asp:BoundField DataField="NAME" HeaderText="NAME" ReadOnly="True" SortExpression="NAME" />
                    <asp:BoundField DataField="TITLE" HeaderText="TITLE" ReadOnly="True" SortExpression="TITLE" />
                    <asp:BoundField DataField="CHECKTIME" HeaderText="CHECKTIME" SortExpression="CHECKTIME" />
                    <asp:BoundField DataField="CHECKTYPE" HeaderText="CHECKTYPE" SortExpression="CHECKTYPE" />
                    <asp:BoundField DataField="trans" HeaderText="Transaction" InsertVisible="False" ReadOnly="True" SortExpression="trans" />
                </Columns>
                <EditRowStyle BackColor="#7C6F57" />
                <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#E3EAEB" />
                <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#F8FAFA" />
                <SortedAscendingHeaderStyle BackColor="#246B61" />
                <SortedDescendingCellStyle BackColor="#D4DFE1" />
                <SortedDescendingHeaderStyle BackColor="#15524A" />
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Button ID="btnReport" runat="server" OnClick="btnReport_Click" Text="Reports" />
    <br />
    <br />
    <br />
    <br />
    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" GroupTreeImagesFolderUrl="" Height="1202px" ToolbarImagesFolderUrl="" ToolPanelWidth="200px" Width="1104px" />
    <br />
    <br />
    <br />
    <br />
</asp:Content>

Problem:

You are using WriteXmlSchema which returns only schema of the DataSet .

Solution:

Change it to WriteXml and you will get the values of the DataSet .

ds.WriteXml("D:\\Sample2.xml");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM