简体   繁体   English

使用vb.net从数据集/数据表更新mysql

[英]update mysql from dataset/datatable with vb.net

I am new to vb.net and I am trying to update mysql table from a txt file using vb.net. 我是vb.net的新手,正在尝试使用vb.net从txt文件更新mysql表。 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. 到目前为止,我已经在这里和那里找到了代码,并且能够从txt文件提取数据,现在我的问题是如何从相同的数据集或xml文件更新mysql。 Here is my code to populate the datagrid/dataset/xml file. 这是我的代码,用于填充datagrid / dataset / xml文件。 Can you tell me what is the easiest way to update mysql assuming "Orden" is my primary key in mysql. 您能否告诉我,假设“ Orden”是我在mysql中的主键,那么更新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(OpenFileDialog1.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) = 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. 在这种情况下,您可以完全跳过生成XML文件。 Load the file directly onto MySQL using " LOAD DATA INFILE ". 使用“ LOAD DATA INFILE ”将文件直接加载到MySQL上。

If necessary, load onto a staging table first, and then perform the update using that table. 如有必要,请先加载到暂存表上,然后使用该表执行更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM