using System;
using System.Data;
using System.Xml;
using System.Data.SqlClient;public class Sample
{
public static void Main()
{
DataSet dsNorthwind = new DataSet(); //Create the connection string.
String sConnect;
sConnect="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind";
//Create a connection object to connect to the northwind db.
SqlConnection nwconnect = new SqlConnection(sConnect); //Create a command string to select all the customers in the WA region.
String sCommand = "Select * from Customers where Region='WA'"; //Create an adapter to load the DataSet.
SqlDataAdapter myDataAdapter = new SqlDataAdapter(sCommand, nwconnect); //Fill the DataSet with the selected records.
myDataAdapter.Fill(dsNorthwind,"Customers"); //Load the document with the DataSet.
XmlDataDocument doc = new XmlDataDocument(dsNorthwind); //Display the XmlDataDocument.
doc.Save(Console.Out);
}
}
using System.Data;
using System.Xml;
using System.Data.SqlClient;public class Sample
{
public static void Main()
{
DataSet dsNorthwind = new DataSet(); //Create the connection string.
String sConnect;
sConnect="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind";
//Create a connection object to connect to the northwind db.
SqlConnection nwconnect = new SqlConnection(sConnect); //Create a command string to select all the customers in the WA region.
String sCommand = "Select * from Customers where Region='WA'"; //Create an adapter to load the DataSet.
SqlDataAdapter myDataAdapter = new SqlDataAdapter(sCommand, nwconnect); //Fill the DataSet with the selected records.
myDataAdapter.Fill(dsNorthwind,"Customers"); //Load the document with the DataSet.
XmlDataDocument doc = new XmlDataDocument(dsNorthwind); //Display the XmlDataDocument.
doc.Save(Console.Out);
}
}
解决方案 »
- 截图坐标问题!
- 如何用c#实现声音数据混合
- 数据库连接问题
- 急死了,,如何将datagridview中的值和textBox进行绑定,,谢谢
- Visual Studio 2008与SQL2005连接问题?
- 第一次学C# 希望大家给点指点 散分
- 請教各位兩個問題! 我每次最多吸能給100分, 沒辦法, 開三貼!
- sql 和datagridview 的问题
- c# UDP 问题 【在线】
- C#怎么调用编译方式为<<嵌入的资源>>的dll文件
- ▲▲▲大家好,用VC#.NET做的程序用 Installshield 制作的安装程序,能保证在win95,win98,winMe,win2000下运行吗?
- Visual Studio 6英文版和Visual Studio.NET英文版的小问题。
public OleDbConnection cn = new OleDbConnection();
public OleDbCommand cm = new OleDbCommand() ;
private OleDbDataAdapter da = new OleDbDataAdapter();
Xml XMLFile1=new Xml();
cn.ConnectionString=strconn;
cm.Connection=cn;
cm.CommandText="select CustID,CustName,QQ,Email from tongxin";
da.SelectCommand=cm;
DataSet ds=new DataSet();
da.Fill(ds,"tongxin");
try
{
ds.WriteXml(Request.MapPath(XMLFile1.xml));
}
catch(Exception)
{
}
finally
{
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
}