Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C将记录添加到关系XML_C#_Xml_Xsd_Dataset - Fatal编程技术网

C# 使用C将记录添加到关系XML

C# 使用C将记录添加到关系XML,c#,xml,xsd,dataset,C#,Xml,Xsd,Dataset,我有一个XML和XSD,我想用Dataset向trck表添加一条记录,我也在编写代码,但需要trackListrow。。。 我怎么办 playListDS rec = new playListDS(); if(File.Exists(Server.MapPath("~/playlist.xml"))) rec.ReadXml(Server.MapPath("~/playlist.xml")); int id =

我有一个XML和XSD,我想用Dataset向trck表添加一条记录,我也在编写代码,但需要trackListrow。。。 我怎么办

playListDS rec = new playListDS();
            if(File.Exists(Server.MapPath("~/playlist.xml")))
                rec.ReadXml(Server.MapPath("~/playlist.xml"));


            int id = int.Parse(rec.track.Rows[rec.track.Rows.Count - 1][0].ToString()) + 1;

            if (ViewState["Filename"] != null && ViewState["Cover"] != null)
            {
                playListDS.trackListRow row  = new playListDS.trackListRow();
                  rec.track.AddtrackRow(id.ToString(), "mp3/" + ViewState["Filename"].ToString(), txtartist.Text,
                  txtalbum.Text, txttitle.Text,
                  txtannotation.Text, txtduration.Text, "mp3/cover" + ViewState["Cover"].ToString(),
                  txtinfo.Text, txtlink.Text);

你的意思是这样的:

playListDS rec = new playListDS();
if(File.Exists(Server.MapPath("~/playlist.xml")))
{
    rec.ReadXml(Server.MapPath("~/playlist.xml"));
}

int id = int.Parse(rec.track.Rows[rec.track.Rows.Count - 1][0].ToString()) + 1;

if (ViewState["Filename"] != null && ViewState["Cover"] != null)
{
    playListDS.trackListRow row = rec.track.AddtrackRow(id.ToString(), "mp3/" +
                              ViewState["Filename"].ToString(), txtartist.Text,
                              txtalbum.Text, txttitle.Text,
                              txtannotation.Text, txtduration.Text, "mp3/cover" +
                              ViewState["Cover"].ToString(),
                              txtinfo.Text, txtlink.Text);
}

您所需要的只是新添加的行?如果是这样的话,您将从AddtrackRow方法中获得新行。

是的,但是这样操作xml。Dew mp3播放器看不到两个曲目列表表

     <trackList>
    <track>
      <FileID>6</FileID>
      <location>mp3/Gomez - See The World-1.mp3</location>
      <creator>Gomez</creator>
      <album>How We Operate</album>
      <title>See the World</title>
      <annotation>Buraya kendi yorumun gelicek boş kalabilir</annotation>
      <duration>243670</duration>
      <image>mp3/coverChrysanthemum.jpg</image>
      <info />
      <link>Grubun bi sitesi fln varsa buraya yazabilisin yoksa beni sil</link>
    </track>
  </trackList>
  <trackList>
    <track>
      <FileID>8</FileID>
      <location>mp3/Archives - Sleepdriving.mp3</location>
      <creator>Grand Archives</creator>
      <album>KEXP</album>
      <title>Sleepdriving</title>
      <annotation>Buraya kendi yorumun gelicek boş kalabilir</annotation>
      <duration>323562</duration>
      <image>mp3/coverDesert.jpg</image>
      <info>PITCHFORK / FORKCAST
http://pitchforkmedia.com</info>
      <link>Grubun bi sitesi fln varsa buraya yazabilisin yoksa beni sil</link>
    </track>
  </trackList>

您可能希望编辑原始帖子,而不是将您的回复作为答案发布。看看如果我没有得到一个好答案怎么办?在常见问题解答中。
playListDS rec = new playListDS();
if(File.Exists(Server.MapPath("~/playlist.xml")))
{
    rec.ReadXml(Server.MapPath("~/playlist.xml"));
}

int id = int.Parse(rec.track.Rows[rec.track.Rows.Count - 1][0].ToString()) + 1;

if (ViewState["Filename"] != null && ViewState["Cover"] != null)
{
    playListDS.trackListRow row = rec.track.AddtrackRow(id.ToString(), "mp3/" +
                              ViewState["Filename"].ToString(), txtartist.Text,
                              txtalbum.Text, txttitle.Text,
                              txtannotation.Text, txtduration.Text, "mp3/cover" +
                              ViewState["Cover"].ToString(),
                              txtinfo.Text, txtlink.Text);
}
     <trackList>
    <track>
      <FileID>6</FileID>
      <location>mp3/Gomez - See The World-1.mp3</location>
      <creator>Gomez</creator>
      <album>How We Operate</album>
      <title>See the World</title>
      <annotation>Buraya kendi yorumun gelicek boş kalabilir</annotation>
      <duration>243670</duration>
      <image>mp3/coverChrysanthemum.jpg</image>
      <info />
      <link>Grubun bi sitesi fln varsa buraya yazabilisin yoksa beni sil</link>
    </track>
  </trackList>
  <trackList>
    <track>
      <FileID>8</FileID>
      <location>mp3/Archives - Sleepdriving.mp3</location>
      <creator>Grand Archives</creator>
      <album>KEXP</album>
      <title>Sleepdriving</title>
      <annotation>Buraya kendi yorumun gelicek boş kalabilir</annotation>
      <duration>323562</duration>
      <image>mp3/coverDesert.jpg</image>
      <info>PITCHFORK / FORKCAST
http://pitchforkmedia.com</info>
      <link>Grubun bi sitesi fln varsa buraya yazabilisin yoksa beni sil</link>
    </track>
  </trackList>