导出到XML时我的表单冻结

时间:2013-07-29 11:45:04

标签: sql-server xml vb.net

这是正常的吗?当我从14k记录中将数据导出到XML时,我无法单击表单中的任何内容?我认为我的表格冻结了。我在从数据库导出文件时使用vb.net。希望听到积极的回应。

代码:

    Using xmlWriter As XmlWriter = xmlWriter.Create(oFileName, xmlSetting)

                    xmlWriter.WriteStartDocument()
                    xmlWriter.WriteStartElement("Products")
                    xmlWriter.WriteAttributeString("type", "array")

                    oDotNet.SqlDb.strCommand = "SELECT IsNULL(SuppCatNum, '') [Stock No], " & _
                                                " ItemCode, " & _
                                                " IsNULL(CodeBars, '') [BardCode List], " & _
                                                " IsNULL(FrgnName, '') [FrgnName], " & _
                                                " ItemName, " & _
                                                " IsNULL(InvntryUom, '') [InvntryUom], " & _
                                                " b.ItmsGrpCod [Category Code], " & _
                                                " b.ItmsGrpNam [Category Name], " & _
                                                " a.QryGroup1 [Allow Decimal], " & _
                                                " Vat.Rate, " & _
                                                " a.ManSerNum, " & _
                                                " IsNULL(a.CardCode, '-1') [CardCode]" & _
                                                " FROM OITM a" & _
                                                " INNER JOIN OITB b ON a.ItmsGrpCod = b.ItmsGrpCod " & _
                                                " INNER JOIN OVTG Vat ON a.VatGourpSa = Vat.Code " '& _
'" WHERE ItemCode = 'Davies EL-0020 White'"
                    ts_Progress.Maximum = oDotNet.SqlDb.Ds.Tables(0).DefaultView.Count

                    For i As Integer = 0 To oDotNet.SqlDb.Ds.Tables(0).DefaultView.Count - 1

                        xmlWriter.WriteStartElement("Product")
                        xmlWriter.WriteElementString("id", -1)
                        xmlWriter.WriteElementString("stock_no", oDotNet.SqlDb.GetField(i, "Stock No"))
                        xmlWriter.WriteElementString("reference", oDotNet.SqlDb.GetField(i, "ItemCode"))

                        xmlWriter.WriteElementString("name", oDotNet.SqlDb.GetField(i, "ItemName"))
                        xmlWriter.WriteElementString("short_name", oDotNet.SqlDb.GetField(i, "FrgnName"))
                        xmlWriter.WriteElementString("supplier_code", oDotNet.SqlDb.GetField(i, "CardCode"))

'*BardCode*'
                        Select Case oType
                            Case 1
Dim _BardCode As String = Nothing
                                oSql.strCommand = "SELECT BcdCode FROM OBCD bcd INNER JOIN OUOM uom ON bcd.UomEntry = uom.UomEntry " & _
                                                    " WHERE ItemCode = '" & oDotNet.SqlDb.GetField(i, "ItemCode") & "' AND bcd.BcdCode != '" & oDotNet.SqlDb.GetField(i, "BardCode List") & "' " & _
                                                    " /*AND uom.UomCode = '" & oDotNet.SqlDb.GetField(i, "InvntryUom") & "'*/ "
                                If oSql.Ds.Tables(0).DefaultView.Count > 0 Then
                                    For oBardCode As Integer = 0 To oSql.Ds.Tables(0).DefaultView.Count - 1
                                        _BardCode &= oSql.GetField(oBardCode).ToString & ", "
                                    Next
                                    _BardCode = oDotNet.SqlDb.GetField(i, "BardCode List") & ", " & _BardCode.Substring(0, _BardCode.Length - 2)

                                Else
                                    _BardCode = oDotNet.SqlDb.GetField(i, "BardCode List")

                                End If


                                xmlWriter.WriteElementString("barcode_list", _BardCode)
                                xmlWriter.WriteElementString("category_id", -1) 
                                xmlWriter.WriteElementString("unit_name", oDotNet.SqlDb.GetField(i, "InvntryUom")) 'oDotNet.SqlDb.GetField(i, "InvntryUom"))
                                xmlWriter.WriteElementString("retail_price", "")

'*WhsCode Here*'
Dim _WhsCode As String = Nothing
                                oSql.strCommand = "SELECT WhsCode FROM OITW WHERE ItemCode = '" & oDotNet.SqlDb.GetField(i, "ItemCode") & "' "
                                For oWhsCode As Integer = 0 To oSql.Ds.Tables(0).DefaultView.Count - 1
                                    _WhsCode &= oSql.GetField(oWhsCode).ToString & ", "
                                Next

                                _WhsCode = _WhsCode.Substring(0, _WhsCode.Length - 2)

                        End Select


                        xmlWriter.WriteEndElement()
                        ts_Value += 1

                        ts_Progress.Value = ts_Value 
                    Next

                    xmlWriter.WriteEndElement()
                    xmlWriter.WriteEndDocument()

                End Using

1 个答案:

答案 0 :(得分:1)

你可以尝试Application.DoEvents这是一个非常草率但很容易解决你的问题。它将允许您使用表单,但它将非常慢。