开发者

update mysql from dataset/datatable with vb.net

开发者 https://www.devze.com 2023-02-27 08:51 出处:网络
I am new to vb.net and I am trying to update mysql table from a txt file using vb.net. So far I\'ve found code here and there and been able to extract the data from the txt file, now my question is ho

I am new to vb.net and I am trying to update mysql table from a txt file using vb.net. So far I've found code here and there and been able to extract the data from the txt file, now my question is how to update mysql from the same dataset or xml file. Here is my code to populate the datagrid/dataset/xml file. Can you tell me what is the easiest way to update mysql assuming "Orden" is my primary key in mysql.

     OpenFileDialog1.Filter = "Text File|*.txt"
    OpenFileDialog1.Title = "Open File..."
    OpenFileDialog1.FileName = "trackings"

    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

        Dim DT As New DataTable
        DT.Columns.Add("COD")
        DT.Columns.Add("Tracking")
        DT.Columns.Add("Fecha")
        DT.Columns.Add("Orden")
        DT.Columns.Add("Estatus")


        Dim Lines() As String = System.IO.File.ReadAllLines(OpenFil开发者_开发知识库eDialog1.FileName)

        For Each Line As String In Lines
            Dim ItemsOf() As String = Split(Line, " ")
            ItemsOf = Line.Split(New String() {" "}, StringSplitOptions.RemoveEmptyEntries)
            If ItemsOf(0) = "N" Then ItemsOf(4) = 3 Else ItemsOf(4) = 6
            Dim NRow As String() = {ItemsOf(0), ItemsOf(1), ItemsOf(2), ItemsOf(3), ItemsOf(4)}
            DT.Rows.Add(NRow)
        Next Line
        DataGridView1.DataSource = DT
        Dim ds As New DataSet
        ds.Tables.Add(DT)
        ds.WriteXml("c:\x.xml")
    End If

Any help is appreciated! And with some code even more! =0)


Based on your code, it looks like your flat file isn't formatted in a complicated manner. If this is the case, you can skip generating the XML file altogether. Load the file directly onto MySQL using "LOAD DATA INFILE".

If necessary, load onto a staging table first, and then perform the update using that table.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号