By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,098 Members | 1,893 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,098 IT Pros & Developers. It's quick & easy.

URGENT Error: CS0117: 'System.Data.DataTable' does not contain a definition for 'WriteXml'

P: n/a
Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: CS0117: 'System.Data.DataTable' does not contain a
definition for 'WriteXml'

Source Error:

Line 55: da.Fill(Datos, "Datos");
Line 56: Session["Tabla"]=ListaTabla.SelectedItem.Text;
Line 57:
Datos.Tables["Datos"].WriteXml(Server.MapPath(Session["Tabla"] + ".xml"));
Line 58: DataGrid1.DataSource=Datos;
Line 59: DataGrid1.DataBind();
Source File: c:\inetpub\wwwroot\PDM\excel\Default.aspx Line: 57

The code:
<%@ Page Language="c#" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Xml" %>
<%@ import Namespace="System.Xml.Xsl" %>
<%@ import Namespace="System.Data.SqlClient" %>
<HTML>
<HEAD>
<script runat="server">

//definimos como publica la conexion a la base de datos
public SqlConnection conDB = new SqlConnection();

public void Page_Load(Object sender, EventArgs E) {
//la primera vez que carga la pagina obtenemos la lista de Bases de
datos
if (Page.IsPostBack == false) {
conDB.ConnectionString = "data
source=10.195.17.7;database=devnew;uid=cuprykma;pw d=ehs123";
/*con "sp_databases" obtenemos la lista de bases de datos en una
instancia de SQL Server
para MySQL se usa "show databases" */
SqlDataAdapter da = new SqlDataAdapter("sp_databases", conDB);
DataSet ds = new DataSet();
da.Fill(ds, "DBases");
ListaDB.DataSource=ds;
//filtramos los datos y solo asociamos la columna "DATABASE_NAME" al
dropdownlist
ListaDB.DataTextField="DATABASE_NAME";
ListaDB.DataBind();
}
}

void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) {
//como ya el usuario selecciono una base de datos activamos el boton
de consultas
Consultar.Enabled=true;
conDB.ConnectionString = "data source=10.195.17.7;initial catalog="
+ ListaDB.SelectedItem.Text + ";integrated security=SSPI;persist security
info=False;uid=cuprykma;pwd=ehs123;packet size=4096";
/*con la cosulta "select * from SYSOBJECTS where TYPE = 'U' and name
<> 'dtproperties' order by NAME"
obtenemos todas las tablas de usuario que hay en una base de datos.
en MySQL usamos "show tables" y en Oracle Usamos "select * from
tab;"*/
SqlDataAdapter da = new SqlDataAdapter("select * from SYSOBJECTS
where TYPE = 'U' and name <> 'dtproperties' order by NAME", conDB);
DataSet ds = new DataSet();
da.Fill(ds, "Tablas");
ListaTabla.DataSource=ds;
//filtramos de nuevo, ahora solo nos intersa la columna "name" con
los nombres de la tablas
ListaTabla.DataTextField="name";
ListaTabla.DataBind();
//aparecemos el boton para hacer la conversion a excel
Convertir.Visible=false;
//y desaparecemos el de consulta
Consultar.Visible=true;
}

public DataSet Datos = new DataSet();

public void Consultar_Click(object sender, EventArgs e) {
conDB.ConnectionString = "data source=10.195.17.7;initial catalog="
+ ListaDB.SelectedItem.Text + ";integrated security=SSPI;persist security
info=False;uid=cuprykma;pwd=ehs123;packet size=4096";
//traemos los datos de la tabla usando la BD selecionada en
ListaTabla y la tabla seleccionada
SqlDataAdapter da = new SqlDataAdapter("select * from " +
ListaTabla.SelectedItem.Text, conDB);
da.Fill(Datos, "Datos");
Session["Tabla"]=ListaTabla.SelectedItem.Text;
Datos.Tables["Datos"].WriteXml(Server.MapPath(Session["Tabla"] +
".xml"));
DataGrid1.DataSource=Datos;
DataGrid1.DataBind();
Consultar.Visible=false;
Convertir.Visible=true;
}

void Button1_Click(object sender, EventArgs e) {
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath(Session["Tabla"] + ".xml"));
XmlDataDocument xdd = new XmlDataDocument(ds);
XslTransform xt = new XslTransform();
xt.Load(Server.MapPath("Excel.xsl"));
xt.Transform(xdd, null, Response.OutputStream);
Response.End();
}

</script>
</HEAD>
<body>
<form runat="server" ID="Form1">
<asp:HyperLink id="HyperLink1" runat="server"
NavigateUrl="Back">Properties</asp:HyperLink>
<table cellspacing="3" cellpadding="7" align="center">
<tbody>
<tr>
<td>
Database</td>
<td>
Table</td>
</tr>
<tr>
<td>
<asp:DropDownList id="ListaDB"
runat="server" OnSelectedIndexChanged="DropDownList1_SelectedInde xChanged"

AutoPostBack="True"></asp:DropDownList>
</td>
<td>
<asp:DropDownList id="ListaTabla"
runat="server">
<asp:ListItem
Value="(Tablas)">(Tables)</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<asp:Button id="Consultar"
onclick="Consultar_Click" runat="server" Text="Consultar"
Enabled="False"></asp:Button>
<asp:Button id="Convertir"
onclick="Button1_Click" runat="server" Text="Convert To Excel"
Visible="False"></asp:Button>
</div>
</td>
</tr>
</tbody>
</table>
<p>
</p>
<p align="center">
<asp:DataGrid id="DataGrid1" runat="server"
BorderStyle="None" BorderWidth="1px" BorderColor="#CC9966"
BackColor="White" CellPadding="4">
<FooterStyle forecolor="#330099"
backcolor="#FFFFCC"></FooterStyle>
<HeaderStyle font-bold="True" forecolor="#FFFFCC"
backcolor="#990000"></HeaderStyle>
<PagerStyle horizontalalign="Center"
forecolor="#330099" backcolor="#FFFFCC"></PagerStyle>
<SelectedItemStyle font-bold="True"
forecolor="#663399" backcolor="#FFCC66"></SelectedItemStyle>
<ItemStyle forecolor="#330099"
backcolor="White"></ItemStyle>
</asp:DataGrid>
</p>
</form>
</body>
</HTML>

--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 3.
MIEMBRO ACTIVO DE ALIANZADEV
http://spaces.msn.com/members/extremed/
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Vko
This method is only defined for DataSet not for DataTable.

Replace :
Datos.Tables["Datos"].WriteXml(Server.MapPath(Session["Tabla"] + ".xml"));
by
Datos.WriteXml(Server.MapPath(Session["Tabla"] + ".xml"));
"Luis Esteban Valencia" wrote:
Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: CS0117: 'System.Data.DataTable' does not contain a
definition for 'WriteXml'

Source Error:

Line 55: da.Fill(Datos, "Datos");
Line 56: Session["Tabla"]=ListaTabla.SelectedItem.Text;
Line 57:
Datos.Tables["Datos"].WriteXml(Server.MapPath(Session["Tabla"] + ".xml"));
Line 58: DataGrid1.DataSource=Datos;
Line 59: DataGrid1.DataBind();
Source File: c:\inetpub\wwwroot\PDM\excel\Default.aspx Line: 57

The code:
<%@ Page Language="c#" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Xml" %>
<%@ import Namespace="System.Xml.Xsl" %>
<%@ import Namespace="System.Data.SqlClient" %>
<HTML>
<HEAD>
<script runat="server">

//definimos como publica la conexion a la base de datos
public SqlConnection conDB = new SqlConnection();

public void Page_Load(Object sender, EventArgs E) {
//la primera vez que carga la pagina obtenemos la lista de Bases de
datos
if (Page.IsPostBack == false) {
conDB.ConnectionString = "data
source=10.195.17.7;database=devnew;uid=cuprykma;pw d=ehs123";
/*con "sp_databases" obtenemos la lista de bases de datos en una
instancia de SQL Server
para MySQL se usa "show databases" */
SqlDataAdapter da = new SqlDataAdapter("sp_databases", conDB);
DataSet ds = new DataSet();
da.Fill(ds, "DBases");
ListaDB.DataSource=ds;
//filtramos los datos y solo asociamos la columna "DATABASE_NAME" al
dropdownlist
ListaDB.DataTextField="DATABASE_NAME";
ListaDB.DataBind();
}
}

void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) {
//como ya el usuario selecciono una base de datos activamos el boton
de consultas
Consultar.Enabled=true;
conDB.ConnectionString = "data source=10.195.17.7;initial catalog="
+ ListaDB.SelectedItem.Text + ";integrated security=SSPI;persist security
info=False;uid=cuprykma;pwd=ehs123;packet size=4096";
/*con la cosulta "select * from SYSOBJECTS where TYPE = 'U' and name
<> 'dtproperties' order by NAME"
obtenemos todas las tablas de usuario que hay en una base de datos.
en MySQL usamos "show tables" y en Oracle Usamos "select * from
tab;"*/
SqlDataAdapter da = new SqlDataAdapter("select * from SYSOBJECTS
where TYPE = 'U' and name <> 'dtproperties' order by NAME", conDB);
DataSet ds = new DataSet();
da.Fill(ds, "Tablas");
ListaTabla.DataSource=ds;
//filtramos de nuevo, ahora solo nos intersa la columna "name" con
los nombres de la tablas
ListaTabla.DataTextField="name";
ListaTabla.DataBind();
//aparecemos el boton para hacer la conversion a excel
Convertir.Visible=false;
//y desaparecemos el de consulta
Consultar.Visible=true;
}

public DataSet Datos = new DataSet();

public void Consultar_Click(object sender, EventArgs e) {
conDB.ConnectionString = "data source=10.195.17.7;initial catalog="
+ ListaDB.SelectedItem.Text + ";integrated security=SSPI;persist security
info=False;uid=cuprykma;pwd=ehs123;packet size=4096";
//traemos los datos de la tabla usando la BD selecionada en
ListaTabla y la tabla seleccionada
SqlDataAdapter da = new SqlDataAdapter("select * from " +
ListaTabla.SelectedItem.Text, conDB);
da.Fill(Datos, "Datos");
Session["Tabla"]=ListaTabla.SelectedItem.Text;
Datos.Tables["Datos"].WriteXml(Server.MapPath(Session["Tabla"] +
".xml"));
DataGrid1.DataSource=Datos;
DataGrid1.DataBind();
Consultar.Visible=false;
Convertir.Visible=true;
}

void Button1_Click(object sender, EventArgs e) {
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath(Session["Tabla"] + ".xml"));
XmlDataDocument xdd = new XmlDataDocument(ds);
XslTransform xt = new XslTransform();
xt.Load(Server.MapPath("Excel.xsl"));
xt.Transform(xdd, null, Response.OutputStream);
Response.End();
}

</script>
</HEAD>
<body>
<form runat="server" ID="Form1">
<asp:HyperLink id="HyperLink1" runat="server"
NavigateUrl="Back">Properties</asp:HyperLink>
<table cellspacing="3" cellpadding="7" align="center">
<tbody>
<tr>
<td>
Database</td>
<td>
Table</td>
</tr>
<tr>
<td>
<asp:DropDownList id="ListaDB"
runat="server" OnSelectedIndexChanged="DropDownList1_SelectedInde xChanged"

AutoPostBack="True"></asp:DropDownList>
</td>
<td>
<asp:DropDownList id="ListaTabla"
runat="server">
<asp:ListItem
Value="(Tablas)">(Tables)</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<asp:Button id="Consultar"
onclick="Consultar_Click" runat="server" Text="Consultar"
Enabled="False"></asp:Button>
<asp:Button id="Convertir"
onclick="Button1_Click" runat="server" Text="Convert To Excel"
Visible="False"></asp:Button>
</div>
</td>
</tr>
</tbody>
</table>
<p>
</p>
<p align="center">
<asp:DataGrid id="DataGrid1" runat="server"
BorderStyle="None" BorderWidth="1px" BorderColor="#CC9966"
BackColor="White" CellPadding="4">
<FooterStyle forecolor="#330099"
backcolor="#FFFFCC"></FooterStyle>
<HeaderStyle font-bold="True" forecolor="#FFFFCC"
backcolor="#990000"></HeaderStyle>
<PagerStyle horizontalalign="Center"
forecolor="#330099" backcolor="#FFFFCC"></PagerStyle>
<SelectedItemStyle font-bold="True"
forecolor="#663399" backcolor="#FFCC66"></SelectedItemStyle>
<ItemStyle forecolor="#330099"
backcolor="White"></ItemStyle>
</asp:DataGrid>
</p>
</form>
</body>
</HTML>

--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 3.
MIEMBRO ACTIVO DE ALIANZADEV
http://spaces.msn.com/members/extremed/

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.