找不到第二列

本文关键字:二列 找不到 | 更新日期: 2023-09-27 17:54:46

private void btnmap_Click(object sender, EventArgs e)
{               
   XmlDocument xmldoc = new XmlDocument();                
   con = new System.Data.SqlClient.SqlConnection();
   ds = new DataSet();
   con.ConnectionString = @"Server=MDS-SW02; User ID=sa; Pwd=Admin2011;Initial Catalog=xml;";
   con.Open();
   MessageBox.Show("Database Connected");                
   String sql = "select Pdf_tag,Styles from Xml_Tags";              
   com = new SqlCommand(sql);           
   da = new System.Data.SqlClient.SqlDataAdapter(sql,con);             
   da.Fill(ds, "xml");                
   maxrows = ds.Tables["xml"].Rows.Count;
   StreamReader objReader = new StreamReader(file,Encoding.Default,true);
   do
   {                                           
      string line = objReader.ReadLine();
      string st1 = ">";
      string st2 = "</";
      int end = line.IndexOf(st2);
      if (end != -1 && end > 1)
      {
         st = line.IndexOf(st1);
         en = line.IndexOf(st2);
         int v = en - st;
         sub = line.Substring(st + 1, v - 1);                            
         rchtext.Text = rchtext.Text + sub + "'r'n"; 
      }                     
      for (int i = 0; i < maxrows; i++)
      {
          dRow = ds.Tables["xml"].Rows[i];
          if(dRow[0].ToString ()==line)
          {
              //XmlDocument xmldoc = new XmlDocument();
              XmlNode docNode = xmldoc.CreateXmlDeclaration("1.0", "UTF-8", null);
              xmldoc.AppendChild(docNode);
              XmlNode xmlnode,xmlroot;
              String sqll = "select Dtd_Tag from Xml_Tags where Mapped_Tags_Attributes.Pdf_Tag=Xml_Tags.Pdf_Tag";
              SqlCommand comm = new SqlCommand(sqll);
              SqlDataAdapter daa = new System.Data.SqlClient.SqlDataAdapter(sqll, con);
              daa.Fill(ds1, "xml");
              dRow1 = ds1.Tables["xml"].Rows[i];
              string name = XmlConvert.EncodeName(dRow1.ItemArray.GetValue(0).ToString());
              xmlnode = xmldoc.CreateElement(name);
              XmlNode Doc = xmldoc.CreateDocumentType(name, null, "E:''Rachana_mds''proj''pdfextraction''docbook.dtd", null);
              xmldoc.AppendChild(Doc);
              xmlroot = xmldoc.CreateElement(dRow1.ItemArray.GetValue(0).ToString());
              xmldoc.AppendChild(xmlroot);             
              String sqlll = "select Dtd_Attribute_Name from Mapped_Tags_Attributes where Mapped_Tags_Attributes.Pdf_Tag=Xml_Tags.Pdf_Tag";
              SqlCommand cmd = new SqlCommand(sqlll);
              SqlDataAdapter dt = new System.Data.SqlClient.SqlDataAdapter(sqlll,con);
              dt.Fill(ds2, "xml");
              dRow2 = ds2.Tables["xml"].Rows[i];
              xmlroot = xmldoc.CreateElement(name);
              xmldoc.AppendChild(xmlroot);
              XmlAttribute xmlatt = xmldoc.CreateAttribute(dRow2.ItemArray.GetValue(0).ToString());                                              
              xmlroot.AppendChild(xmlnode);
              xmlnode.InnerText=sub;                       
            }                                                                
            while (objReader.Peek() != -1);
            //string filename = @"E:" + DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Minute + ".xml";
            string filename = @"E:'" + DateTime.Now.ToString("dd/mm/yyyy")+".xml";
            xmldoc.Save(filename); 
            MessageBox.Show("Done");
            con.Close();                                  
}

找不到第二列

啊,现在您已经告诉了我们有错误(注释)的行,问题很明显:

dRow = ds.Tables["xml"].Rows[i];
if(dRow[i].ToString ()==line) {...}

dRow为行;除非您的数据是纯方形的,否则您可能希望访问每行的第一列:

dRow = ds.Tables["xml"].Rows[i];
if(dRow[0].ToString ()==line) {...}