none
請教vb.net 2005 express 讀入XML 批次更新DataSet中的資料 RRS feed

  • 問題

  • 各位先進您好:

    小弟我裕將XML檔案讀入DataSet,然後分析所讀入的資料後再更新另一個DataSet的資料表我將如何作呢??

    以前VB6是使用Recrodset.find指令然後指標就停在要更新的資料錄,就可以直接給值,全部更新完畢後,就可以Update,那在VB.NET 2005該如何模擬呢??

    我的程式碼如下:

        Dim ts As New Data.DataTable
        Private Sub FormWork_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                ts = GetDataSet("Select Flag as 空號,Numb as 傳票編號,AType as 會計科目,C_Mont as 借方金額,D_Mont as 貸方金額 from QA ORDER BY Numb").Tables(0)
                Me.DataGridView1.DataSource = ts
                DataGridViewDefaultStyle()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try

        End Sub

        Private Sub ButtonImports_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonImports.Click
            Me.OpenFileDialog1.Filter = "XML格式檔案(*.xml) | *.xml | 所有類型檔案(*.*) | *.*"
            Me.OpenFileDialog1.FileName = "*.xml"
            Try
                If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                    Dim ImportsDS As New DataSet
                    Dim FindRow As DataRow
                    Dim keys(1) As DataColumn
                    keys(0) = ts.Columns("傳票編號")
                    ts.PrimaryKey = keys

                    ImportsDS.ReadXml(Me.OpenFileDialog1.FileName)

                    For Each ImportsRow As DataRow In ImportsDS.Tables(0).Rows

    --------------------------------------------------------------------------------------------------------

    --------------------------------------------------------------------------------------------------------

                        If FindRow.Item("空號") = "*" Or FindRow.Item("傳票編號") = String.Empty Then

                        Else
                            FindRow.Item("會計科目") = ImportsRow.Item("會計科目")
                            FindRow.Item("借方金額") = ImportsRow.Item("借方金額")
                            FindRow.Item("貸方金額") = ImportsRow.Item("貸方金額")
                        End If
                    Next
                    DataGridView1.DataSource = ts
                    DataGridView1.Refresh()
                    MessageBox.Show("匯入XML檔案格式完成!!")
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub

     

    紅色 -- 號中間該怎麼找到我要的DataRow然後更新,還是有更快更方便的方法呢??

    2006年7月26日 上午 04:00

解答