我想以xml格式转换数据库中的数据 使用c#我已经转换为ino xml格式,但它没有提供有关模式中主键和外键的信息
我的代码是
string[] b = GetAllTables();//array that gives me the name of tables
foreach (string c in b)
{
string sqlText = "SELECT * FROM " + c;
SqlDataAdapter da = new SqlDataAdapter(sqlText, myCon);
da.SelectCommand.CommandType = CommandType.Text;
da.Fill(customer,c);
foreach (DataTable dt1 in customer.Tables)
{
for (int curRow = 0; curRow < dt1.Rows.Count; curRow++)
{
for (int curCol = 0; curCol < dt1.Columns.Count; curCol++)
{
dt1.Rows[curRow][curCol].ToString();
// System.IO.StreamWriter xmlSW = new System.IO.StreamWriter(@"D:\Customer.xml");
}
}
}
}
string xmlDS = customer.GetXml();
customer.WriteXml(xmlSW, XmlWriteMode.WriteSchema);
MessageBox.Show("successfully writed");
xmlSW.Close();
答案 0 :(得分:0)
您可以尝试使用XElement类并设置xml文件的属性,如下所示(仅举例): SqlConnection thisConnection = new SqlConnection(@“Data Source = 3BDALLAH-PC; Initial Catalog = XMLC; Integrated Security = True; Pooling = False;”); thisConnection.Open();
XElement eventsGive =
new XElement("data",
from c in ??????
select new XElement("event",
new XAttribute("start", c.start),
new XAttribute("end",c.eend),
new XAttribute("title",c.title),
new XAttribute("Color",c.Color),
new XAttribute("link",c.link)));
Console.WriteLine(eventsGive);
然后将数据库的列标签及其名称放在xml文件中。
此致
Otacon。