ijust finish my code for inserting data using the vb and mySQL but when i run my webpage it seem have an error Fatal Error Encounter During Command Execution . Please help some how to solve it. below is my code.
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
解决方案
you probably forgot to add this parameter @IDCR
.Parameters.AddWithValue("@IDCR", toyourvariable)