mysql - 命令执行期间遇到 fatal error MySQL VB

标签 mysql asp.net vb.net

我刚刚完成了使用 vb 和 mySQL 插入数据的代码,但是当我运行我的网页时,它似乎有一个错误 Fatal Error Encounter During Command Execution 。请帮助一些如何解决它。下面是我的代码。

Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient


Partial Class Request

    Inherits System.Web.UI.Page

    Dim MessageBox As Object

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        txt1.Focus()
        txt2.Focus()
        txt3.Focus()
        txt4.Focus()
        txt5.Focus()
        txt6.Focus()
        txt7.Focus()
        ddl1.Focus()
        ddl2.Focus()
        ddl3.Focus()
        ddl4.Focus()
    End Sub

    Protected Sub btnsubmit_Click(sender As Object, e As EventArgs) Handles btnsubmit.Click


        'Create sql connection and fetch data from database based on employee id

        Dim conn As New MySql.Data.MySqlClient.MySqlConnection

        Dim strConnectionString As String = ConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString

        Try
            conn.ConnectionString = strConnectionString
            conn.Open()

        Catch ex As MySql.Data.MySqlClient.MySqlException
            MessageBox.Show(ex.Message)
        End Try
        '  Dim cr_id As String
        ' cr_id = "CR004"
        Dim iReturn As Boolean
        Using SQLConnection As New MySqlConnection(strConnectionString)
            Using sqlCommand As New MySqlCommand()
                sqlCommand.Connection = SQLConnection
                With sqlCommand




                    .CommandText = "INSERT INTO cr_record(idcr_record,Emplid,Nama,date,DeptDesc,email,change,reasonchange,problem,priority,reasondescription,systemrequest) VALUES (@IDCR,@Emplid,@Nama,@date,@DeptDesc,'@email,@change,@reasonchange,@problem,@priority,@reasondescription,@systemrequest)"
                    ' .CommandTimeout = 5000000
                    .CommandType = Data.CommandType.Text

                    .Parameters.AddWithValue("@Emplid", txt1.Text)
                    .Parameters.AddWithValue("@Nama", TextBox1.Text)
                    .Parameters.AddWithValue("@date", txt5.Text)
                    .Parameters.AddWithValue("@DeptDesc", txt2.Text)
                    .Parameters.AddWithValue("@email", txt4.Text)
                    .Parameters.AddWithValue("@change", ddl2.Text)
                    .Parameters.AddWithValue("@reasonchange", txt6.Text)
                    .Parameters.AddWithValue("@problem", ddl3.Text)
                    .Parameters.AddWithValue("@priority", rbl1.Text)
                    .Parameters.AddWithValue("@reasondescription", txt7.Text)
                    .Parameters.AddWithValue("@systemrequest", ddl4.Text)




                End With
                Try
                    SQLConnection.Open()
                    ' sqlCommand.ExecuteNonQuery()
                    sqlCommand.ExecuteNonQuery()
                    iReturn = True
                    MsgBox("Added Successfully")
                Catch ex As MySqlException
                    MsgBox(ex.Message.ToString & Err.Description)
                    iReturn = False
                Finally
                    SQLConnection.Close()
                End Try
            End Using
        End Using
        Return
    End Sub



End Class

最佳答案

你可能忘了添加这个参数@IDCR

.Parameters.AddWithValue("@IDCR", toyourvariable)

关于mysql - 命令执行期间遇到 fatal error MySQL VB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22521908/

相关文章:

mysql - 安装 LAMP 时...我应该安装 Apache、MySQL Server 然后是 PHP 还是 Apache、PHP 然后是 MySQL Server?

c# - 需要帮助找出 NullReferenceException

ASP.NET AJAX AsyncFileUpload UploadedComplete 不触发

vb.net - 为什么我收到错误: BC30452 Operator '&' is not defined for types 'String' and 'Image' , for this code?

php - MySQL错误: This command is not supported in the prepared statement protocol yet

mysql - Rails 4 表的 SQL 查询使用 .where 正确读取一列,但不能正确读取另一列

Mysql 查询 where condition with Date 不等于 '0000-00-00'

c# - 从 API 请求中删除 Arrafinity Cookie

vb.net - 了解在 VB 的官方约定指南中发现的矛盾

vb.net - Mercury Quick Test Pro 和虚拟机 : Works from one client machine but not another