vb.net 的 Oracle 数据库错误
Oracle database errors with vb.net
我的任务是制作一个简单的基于 GUI 的数据库查看器。数据库托管在我们学校 ftp 服务器上,我们必须使用 visual basic,大部分情况下我都可以使用它 我可以搜索、查看和添加到数据库,但是编辑现有记录给我带来了问题.
当我尝试更新记录时,在查询的 where 部分未使用冒号 (:) 时出现 ora-00904 错误无效标识符,并且出现 ora-01008 不是用冒号 (:) 绑定的变量。到目前为止,我们只真正使用过 sqldeveloper,作为最终项目,我们被要求使用 Visual Basic,但我们从未在 class 中介绍过类似的内容,所以我认为这是一个挑战。
PS: 我只注释掉了那部分,以便我可以查看错误。
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim strCustomerEmail As String = ""
Dim strLastName As String = ""
Dim strFirstName As String = ""
Dim strAddress As String = ""
Dim strCity As String = ""
Dim strState As String = ""
Dim intZip As Integer = 0
Dim datDateSignedUp As Date
Dim intCustomerNumber As Integer = 0
Try
strCustomerEmail = CStr(txtCustomerEmail.Text)
strLastName = CStr(txtLastName.Text)
strFirstName = CStr(txtFirstName.Text)
strAddress = CStr(txtAddress.Text)
strCity = CStr(txtCity.Text)
strState = CStr(txtState.Text)
intZip = CInt(txtZip.Text)
datDateSignedUp = CDate(txtDateSignedUp.Text)
intCustomerNumber = CInt(txtCustomerNumber.Text)
Dim sql As String = "UPDATE P_CLIENTS SET CUSTOMER_EMAIL = :CUSTOMER_EMAIL, LASTNAME = :LASTNAME, FIRSTNAME = :FIRSTNAME, ADDRESS = :ADDRESS, CITY = :CITY, STATE = :STATE, ZIP = :ZIP, DATE_SIGNED_UP = :DATE_SIGNED_UP, CUSTOMER# = :CUSTOMER# WHERE CUSTOMER_EMAIL = :EDIT_CUSTOMER_EMAIL"
Dim cmd2 As New OracleCommand(sql, conn)
conn.Open()
cmd2.Parameters.Add("CUSTOMER_EMAIL", strCustomerEmail)
cmd2.Parameters.Add("LASTNAME", strLastName)
cmd2.Parameters.Add("FIRSTNAME", strFirstName)
cmd2.Parameters.Add("ADDRESS", strAddress)
cmd2.Parameters.Add("CITY", strCity)
cmd2.Parameters.Add("STATE", strState)
cmd2.Parameters.Add("ZIP", intZip)
cmd2.Parameters.Add("DATE_SIGNED_UP", datDateSignedUp)
cmd2.Parameters.Add("EDIT_CUSTOMER_EMAIL", strEditCustomerEmail)
cmd2.CommandType = CommandType.Text
cmd2.ExecuteNonQuery()
txtCustomerEmail.Text = strEditCustomerEmail
txtLastName.Text = ""
txtFirstName.Text = ""
txtAddress.Text = ""
txtCity.Text = ""
txtState.Text = ""
txtZip.Clear()
txtDateSignedUp.Clear()
txtCustomerNumber.Clear()
'txtCustomerEmail.Select()
txtCustomerEmail.Enabled = True
txtLastName.Enabled = True
txtFirstName.Enabled = True
txtAddress.Enabled = True
txtCity.Enabled = True
txtState.Enabled = True
txtZip.Enabled = True
txtDateSignedUp.Enabled = True
txtCustomerNumber.Enabled = True
'Catch ex As Exception
' MessageBox.Show("An error occurred while attempting to add a new record.", "Error")
Finally
conn.Close()
txtCustomerEmail.Select()
End Try
End Sub
您的参数列表中缺少 Customer#
。
我的任务是制作一个简单的基于 GUI 的数据库查看器。数据库托管在我们学校 ftp 服务器上,我们必须使用 visual basic,大部分情况下我都可以使用它 我可以搜索、查看和添加到数据库,但是编辑现有记录给我带来了问题.
当我尝试更新记录时,在查询的 where 部分未使用冒号 (:) 时出现 ora-00904 错误无效标识符,并且出现 ora-01008 不是用冒号 (:) 绑定的变量。到目前为止,我们只真正使用过 sqldeveloper,作为最终项目,我们被要求使用 Visual Basic,但我们从未在 class 中介绍过类似的内容,所以我认为这是一个挑战。
PS: 我只注释掉了那部分,以便我可以查看错误。
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim strCustomerEmail As String = ""
Dim strLastName As String = ""
Dim strFirstName As String = ""
Dim strAddress As String = ""
Dim strCity As String = ""
Dim strState As String = ""
Dim intZip As Integer = 0
Dim datDateSignedUp As Date
Dim intCustomerNumber As Integer = 0
Try
strCustomerEmail = CStr(txtCustomerEmail.Text)
strLastName = CStr(txtLastName.Text)
strFirstName = CStr(txtFirstName.Text)
strAddress = CStr(txtAddress.Text)
strCity = CStr(txtCity.Text)
strState = CStr(txtState.Text)
intZip = CInt(txtZip.Text)
datDateSignedUp = CDate(txtDateSignedUp.Text)
intCustomerNumber = CInt(txtCustomerNumber.Text)
Dim sql As String = "UPDATE P_CLIENTS SET CUSTOMER_EMAIL = :CUSTOMER_EMAIL, LASTNAME = :LASTNAME, FIRSTNAME = :FIRSTNAME, ADDRESS = :ADDRESS, CITY = :CITY, STATE = :STATE, ZIP = :ZIP, DATE_SIGNED_UP = :DATE_SIGNED_UP, CUSTOMER# = :CUSTOMER# WHERE CUSTOMER_EMAIL = :EDIT_CUSTOMER_EMAIL"
Dim cmd2 As New OracleCommand(sql, conn)
conn.Open()
cmd2.Parameters.Add("CUSTOMER_EMAIL", strCustomerEmail)
cmd2.Parameters.Add("LASTNAME", strLastName)
cmd2.Parameters.Add("FIRSTNAME", strFirstName)
cmd2.Parameters.Add("ADDRESS", strAddress)
cmd2.Parameters.Add("CITY", strCity)
cmd2.Parameters.Add("STATE", strState)
cmd2.Parameters.Add("ZIP", intZip)
cmd2.Parameters.Add("DATE_SIGNED_UP", datDateSignedUp)
cmd2.Parameters.Add("EDIT_CUSTOMER_EMAIL", strEditCustomerEmail)
cmd2.CommandType = CommandType.Text
cmd2.ExecuteNonQuery()
txtCustomerEmail.Text = strEditCustomerEmail
txtLastName.Text = ""
txtFirstName.Text = ""
txtAddress.Text = ""
txtCity.Text = ""
txtState.Text = ""
txtZip.Clear()
txtDateSignedUp.Clear()
txtCustomerNumber.Clear()
'txtCustomerEmail.Select()
txtCustomerEmail.Enabled = True
txtLastName.Enabled = True
txtFirstName.Enabled = True
txtAddress.Enabled = True
txtCity.Enabled = True
txtState.Enabled = True
txtZip.Enabled = True
txtDateSignedUp.Enabled = True
txtCustomerNumber.Enabled = True
'Catch ex As Exception
' MessageBox.Show("An error occurred while attempting to add a new record.", "Error")
Finally
conn.Close()
txtCustomerEmail.Select()
End Try
End Sub
您的参数列表中缺少 Customer#
。