我希望你能帮助我。首先,对不起,如果我的英语很烦人,我不是母语人士。
我收到了这个错误,我看不出我做错了什么。我有一个程序用来自另一个使用 OLEB DB 的程序的数据填充本地 MySQL DB。因此,它会比较表格并按需上传新数据。但是我只有一个表使用与其他表一起使用的相同 Sub 时出现此错误。
“字段列表”中的未知列“lpedidos.serie”
问题是“lpedidos.serie”确实存在。所以这里是子的代码,请不要笑,我知道这可能是非常低效的,但我只是一个菜鸟。
Public Sub notIndexedTables(table As DataTable, table2 As DataTable, tableNA As String)
Dim temptable As DataTable
temptable = table.Clone
Dim tablename As String = temptable.TableName
Dim myAdapter As MySql.Data.MySqlClient.MySqlDataAdapter
Dim SQL As String
Dim newconn As New MySql.Data.MySqlClient.MySqlConnection
newconn = mysqlConnection()
newconn.Open()
SQL = "TRUNCATE " & tableNA
myAdapter = New MySql.Data.MySqlClient.MySqlDataAdapter()
Dim command As MySql.Data.MySqlClient.MySqlCommand
command = New MySql.Data.MySqlClient.MySqlCommand(SQL, newconn)
myAdapter.DeleteCommand = command
myAdapter.DeleteCommand.ExecuteNonQuery()
For Each row As DataRow In table.Rows()
Dim columnNumber As Int32 = row.ItemArray.Count
Dim i As Integer = 0
Dim s1 As String = "("
For Each columna In row.ItemArray
i = i + 1
If i = columnNumber Then
s1 = s1 + CStr(table2.Columns.Item(i - 1).ColumnName) & ")"
Else
s1 = s1 & CStr(table2.Columns.Item(i - 1).ColumnName) & ", "
End If
Next
Dim s2 As String = "("
i = 0
For i = 0 To (columnNumber - 2)
s2 = s2 & "'" & CStr(row.Item(i)) & "', "
Next
s2 = s2 & "'" & CStr(row.Item(columnNumber - 1)) & "')"
SQL = "INSERT INTO " & tableNA & " " & s1 & " VALUES " & s2
myAdapter = New MySql.Data.MySqlClient.MySqlDataAdapter()
' myCommand = New MySql.Data.MySqlClient.MySqlCommandBuilder(myAdapter)
command = New MySql.Data.MySqlClient.MySqlCommand(SQL, newconn)
myAdapter.InsertCommand = command
myAdapter.InsertCommand.ExecuteNonQuery()
Next
newconn.Close()
newconn.Dispose()
End Sub
基本上它需要 MySQL 表(tableNA),截断它(此过程适用于没有索引的表,对于具有唯一索引的表还有其他过程)并用 OLEB 表(表)中的数据填充它并获取列名来自 MySQL 表 (table2) 的临时副本(在这种情况下可能不需要使用 table2 ......但无论如何)。
这是异常和抛出异常时 SQL 字符串所采用的值。
这是phpMyAdmin中表结构的截图。