有这样一个XML数据文件:   
  <?xml   version="1.0"   encoding="GBK"?>   
  <booksite   id="001">   
  <book>   
  <bookid>2001</bookid>   
  <title><![CDATA[C#数据库编程]]></title>   
    
  <author>李先生</author>   
  </book>   
  .......   
  </booksite>   
    
    
  想使用asp.net把它导入到SQL   server中的book表里,请问有那位高手知道这个怎么写?   批处理到 sql server里面 

解决方案 »

  1.   

    dataset里有一个可以把这样格式的xml文件转成dateset.
    然后直接写入数据库就行了.
    insert不用我教了把
      

  2.   

    DataSet   ds   =   new   DataSet();   
    ds.ReadXml(@"c:\x.xml");读取XML数据
    ds.DataSetName ="***";//定义结果集名称
      

  3.   


    For   i   =   0   To   .EpmsDos.Rows.Count   -   1   
                                                      com.CommandText   =   "Select   Count(序号)   From   EpmsDos"   &   Me.dat1.Value.Year   &   "   Where   序号="   &   .EpmsDos(i).序号   
                                                      dr   =   com.ExecuteReader   
                                                      If   dr.Read   Then   
                                                              intCount   =   dr.GetInt32(0)   
                                                      End   If   
                                                      dr.Close()   
                                                      If   intCount   =   0   Then   
                                                              OnInfo("正在向数据库追加数据...")   
                                                              com.CommandText   =   "Insert   Into   ...."   
                                                      Else   
                                                              OnInfo("正在替换数据...")   
                                                              com.CommandText   =   "Update   ..."   
                                                      End   If   
        
                                                      com.ExecuteNonQuery()   
        
                                              Next
    <?xml   version="1.0"   standalone="yes"?>   
      <DataSet1   xmlns="http://www.tempuri.org/DataSet1.xsd">   
          <YYXJ_list>   
              <ID>1</ID>   
              <Tenant>123456</Tenant>   
              <Lease>12345678901234</Lease>   
          </YYXJ_list>   
          <YYXJ_list>   
              <ID>2</ID>   
              <Tenant>654321</Tenant>   
              <Lease>01234567891234</Lease>   
          </YYXJ_list>   
        <YYXJ_list>   
              <ID>3</ID>   
              <Tenant>6876554321</Tenant>   
              <Lease>01234</Lease>   
          </YYXJ_list>   
      <YYXJ_list>   
              <ID>4</ID>   
              <Tenant>654325751</Tenant>   
              <Lease>0127891234</Lease>   
          </YYXJ_list>   
      <YYXJ_list>   
              <ID>5</ID>   
              <Tenant>468654321</Tenant>   
              <Lease>524201234567891234</Lease>   
          </YYXJ_list>   
      <YYXJ_list>   
              <ID>6</ID>   
              <Tenant>654321</Tenant>   
              <Lease>01234567891234</Lease>   
          </YYXJ_list>   
      <YYXJ_list>   
              <ID>7</ID>   
              <Tenant>555555</Tenant>   
              <Lease>55555555555555</Lease>   
          </YYXJ_list>   
      </DataSet1>
      

  4.   

    Private Sub huangguan()
            Dim con As SqlConnection = New SqlConnection("Server=127.0.0.1;Database=123net;UID=sa;PWD=dong;")
            Dim strinsert, strupdate As String
            Dim ret As Integer
            Dim cmdinsert, cmdupdate As SqlCommand
            Dim xmldoc As XmlDocument = New XmlDocument()
            xmldoc.Load("xml/huangguan.xml")
            Dim node As XmlNode = xmldoc.SelectSingleNode("c/match/m")
            con.Open()
            For Each node In xmldoc.SelectNodes("c/match/m")
                Dim node_i As XmlNode = node.SelectSingleNode("i")
                Dim node_co As XmlNode = node.SelectSingleNode("co")
                Dim node_le As XmlNode = node.SelectSingleNode("le")
                Dim node_t As XmlNode = node.SelectSingleNode("t")
                Dim node_ta As XmlNode = node.SelectSingleNode("ta")
                Dim node_tb As XmlNode = node.SelectSingleNode("tb")
                Dim node_zl As XmlNode = node.SelectSingleNode("zl")
                Dim node_p As XmlNode = node.SelectSingleNode("p")
                Dim node_yp As XmlNode = node.SelectSingleNode("yp")
                Dim node_op As XmlNode = node.SelectSingleNode("op")
                Dim node_dxp As XmlNode = node.SelectSingleNode("dxp")
                Dim node_s As XmlNode = node.SelectSingleNode("s")
                Dim node_tv As XmlNode = node.SelectSingleNode("tv")
                Dim i As String = node_i.InnerText            Dim co As String = node_co.InnerText            Dim le As String = node_le.InnerText
                Dim arr_le() As String = le.Split(",")            Dim t As String = node_t.InnerText            Dim ta As String = node_ta.InnerText
                Dim arr_ta() As String = ta.Split(",")            Dim tb As String = node_tb.InnerText
                Dim arr_tb() As String = tb.Split(",")            Dim zl As String = node_zl.InnerText            Dim p As String = node_p.InnerText            Dim yp As String = node_yp.InnerText
                Dim arr_yp() As String = yp.Split(",")            Dim op As String = node_op.InnerText
                Dim arr_op() As String = op.Split(",")            Dim dxp As String = node_dxp.InnerText
                Dim arr_dxp() As String = dxp.Split(",")            Dim s As String = node_s.InnerText
                Dim arr_s() As String = s.Split(",")            Dim tv As String = node_tv.InnerText
                Dim cmd As New SqlCommand("select * from all_odds where id=" & i, con)
                ret = cmd.ExecuteScalar()                strupdate = "update all_odds set ts='" & arr_le(1) & "',ss='" & arr_le(0) & "',es='" & arr_le(2) & "',gt='" & t & "',th='" & arr_ta(1) & "',sh='" & arr_ta(0) & "',eh='" & Replace(arr_ta(2), "'", "''") & "',ta='" & arr_tb(1) & "',sa='" & arr_tb(0) & "',ea='" & Replace(arr_tb(2), "'", "''") & "',hr='" & arr_s(0) & "',ar='" & arr_s(1) & "',zl='" & zl & "',p='" & p & "',hg_gg0='" & arr_yp(1) & "',hg_gg='" & arr_yp(2) & "',hg_ho='" & arr_yp(3) & "',hg_ao='" & arr_yp(4) & "',hg_hwin='" & arr_op(1) & "',hg_awin='" & arr_op(2) & "',hg_draw='" & arr_op(3) & "',hg_pk='" & arr_dxp(1) & "',hg_big='" & arr_dxp(2) & "',hg_small='" & arr_dxp(3) & "',hg_tv='" & tv & "',color='" & co & "' where id=" & i
                    cmdupdate = New SqlCommand(strupdate, con)
                    cmdupdate.ExecuteNonQuery()
                    cmdupdate.Dispose()
                    cmd.Dispose()
            Next node        con.Close()
            con.Dispose()
        End Sub