VB.NET 我正在尝试在Mysql中生成序列号并向数据网格视图显示我的返回查询错误



你好,我试图在Mysql中生成一个序列号,它工作,但当我尝试返回查询vb.net代码时,我得到了一个错误,说

MySql.Data.MySqlClient。MySqlException: '执行命令时遇到致命错误。'内部异常MysqlException:参数'@row'必须定义。

我尝试在Datatable中创建行,但它仍然是一个错误

If ComboBox2.Text = "All" Then
Dim query As String = "SET @row := 0;
SELECT  @row := @row + 1 as row,  concat( firstname, ' ', mname, ' ', lastname ) AS Fullname, barangay as Barangay, nature_of_work as 'Status', level 'Year Level', date(member_since) as 'Date Registered', login_count as 'Number Of Visit' 
FROM blhtraining.userinfo  t, (SELECT @row := 0)  r
Where 
date(member_since) BETWEEN  '" & DateTimePicker4.Value.Date.ToString("yyyy-M-d") & "' AND '" & DateTimePicker3.Value.Date.ToString("yyyy-M-d") & "'
AND login_count >=  '" & TextBox1.Text & "' 
Order by Fullname"
Dim regular_user_table As New DataTable()
Dim regular_user_adapter As New MySqlDataAdapter(query, mycon)
regular_user_adapter.Fill(regular_user_table)
DataGridView1.DataSource = regular_user_table

现在我在这里找到了解决方案https://blog.tjitjing.com/index.php/2009/05/mysqldatamysqlclientmysqlexception-parameter-id-must-be-defined.html

连接应该是这样的将mycon设置为新的MySqlConnection("Server=localhost;Port=3306;Database=blhtraining;Uid=root;Allow User Variables=True")

最新更新