这到了那里的天才,让我们看看你能帮助我。
Imports System
Imports System.Data
' Version 6.5.4.0 Runtime v2.0.50727
Imports MySql.Data.MySqlClient
Public Class MainForm
' Config - Main.
Private db_host As String = ""
Private db_username As String = ""
Private db_userpass As String = ""
Private db_catalog As String = ""
Private db_port As String = "3306"
' Config - Specific Table.
Private db_specific_table As String = "SF6SETUP"
' Config - Other.
Private DS As DataSet
Private DA As MySqlDataAdapter
Private BS As BindingSource
' ***
'
' ***
Private Sub My_Init()
Dim conn As String = "Data Source = " & db_host & ";Initial Catalog=" & db_catalog & "; uid=" & db_username & ";password=" & db_userpass
Dim myConnection As New MySqlConnection(conn)
Dim cmd As String = "SELECT * FROM " & db_specific_table
DA = New MySqlDataAdapter(cmd, myConnection)
' This line of code to generate update commands automatically.
' This update method of would not work without this line of code.
Dim MySQLCommandBuilder As New MySqlCommandBuilder(DA)
myConnection.Open()
DS = New DataSet()
DA.Fill(DS, "MyTable")
BS = New BindingSource
BS.DataSource = DS.Tables(0)
Dim BN As BindingNavigator = New BindingNavigator()
BN.BindingSource = BS
DataGridView.DataSource = BS
End Sub
' ***
'
' ***
Private Sub MainForm_Load(sender As Object, e As System.EventArgs) Handles Me.Load
My_Init()
End Sub
Private Sub DataGridView_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles DataGridView.KeyPress
BS.EndEdit()
DA.Update(DS, "MyTable")
End Sub
End Class有一个错误:
System.Data.dll中发生未处理的类型为“System.InvalidOperationException”的异常
附加信息:对于不返回任何键列信息的SelectCommand,不支持UpdateCommand的动态SQL生成。
此代码的作品除了没有更改保存到MySQL数据库!
请帮我解决这个问题。
谢谢,
麦克风
VB.NET应用程序尝试从数据库加载数据并自动创建更新命令时遇到问题。错误表明`SelectCommand`未返回任何键列信息,导致无法动态生成SQL更新语句。为解决此问题,你需要确保查询返回包含主键列的信息,以便数据适配器能够正确生成更新命令。

2374

被折叠的 条评论
为什么被折叠?



