急!关于利用c# 读取sql2000数据库的数据为xml格式的文件

twp104twp 2009-09-18 05:51:24

下面是“按钮”控件下的代码 目的是读取 sql2000数据库中数据 输出格式为xml的文件


string sqlstr = " select data,discountno,discountname,productno,productname,quantity,price,pihao,unit,type ,accountno,accountname from tslmsyy for xml Auto ";

//Query(sqlstr);
//string yiyao = "XMLFile.xml";
SqlDataAdapter sda = new SqlDataAdapter(sqlstr, mydb.getcon());
DataSet ds =new DataSet ();
sda .Fill (ds,"dstable");
ds.ReadXml(Server.MapPath("./") + "XMLFile.xml"); //+ "/web.config");

DataTable tb=new DataTable ();
DataView dv=new DataView ();
tb = ds.Tables["dstable"] ;
dv=new DataView (tb);
this.GridViewyy.DataSource =dv;
this .GridViewyy .DataBind ();
gridviewread();


或许那位有更好的源代码,请共享一下,谢谢
...全文
135 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
twp104twp 2009-09-20
  • 打赏
  • 举报
回复
wuyq11

(人生如梦)

非常感谢你,你是正确的
tangyong12 2009-09-20
  • 打赏
  • 举报
回复
把数据读取到DataSet里,然后用DataSet.WriteXML()方法写成XML文件,不过这样操作肯定没有你直接用SQL语句写的效率高
wuyq11 2009-09-20
  • 打赏
  • 举报
回复
string filepath = Server.MapPath("A.xml");
ds.WriteXml(filepath);

public static bool WriteXmlByDataSet(string strXmlPath,string[] Columns,string[] ColumnValue)
{
string strXsdPath="";
try
{
string strXsdPath = strXmlPath.Substring(0,strXmlPath.IndexOf(".")) + ".xsd";
DataSet ds = new DataSet();
ds.ReadXmlSchema(strXsdPath);
ds.ReadXml(strXmlPath);
DataTable dt = ds.Tables[0];
DataRow newRow = dt.NewRow();
for(int i=0; i< Columns.Length; i++)
{
newRow[Columns[i]] = ColumnValue[i];
}
dt.Rows.Add(newRow);
dt.AcceptChanges();
ds.AcceptChanges();
ds.WriteXml(strXmlPath);
return true;
}
catch(Exception)
{
return false;
}
}
xie_yanke 2009-09-20
  • 打赏
  • 举报
回复
Convert.ToString(..ExecuteScalar()); //输出的是一个单列单行的XML数据。
twp104twp 2009-09-20
  • 打赏
  • 举报
回复
没有报错,但是没有达到目的,目的是以xml格式文件输出sql2000的数据库中的数据

我想能不能给出c#源代码也可以,我这个源代码也是网络上找,不确定是否正确

请帮忙吧?
谢谢?
twp104twp 2009-09-20
  • 打赏
  • 举报
回复
我们的客户要求导出来的xml格式是这样的,请看下面

<?xml version="1.0" encoding="utf" ?>
<NewDataSet>
<table>
<字段名>对应的数据</字段名>
.
.
.
</table>
</NewDataSet>
twp104twp 2009-09-20
  • 打赏
  • 举报
回复
wuyq11

(人生如梦)


你好:

我是利用你这段代码成功生成了

xml文件

但是这个xml文件是保存在服务器端,我要让他在客户端浏览保存在客户端

怎么实现?

谢谢
优途科技 2009-09-19
  • 打赏
  • 举报
回复
问题好像不是很具体啊。
gisyellow 2009-09-18
  • 打赏
  • 举报
回复
问题是什么啊,报什么错?

111,083

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧