If ComboBox1.Text = "New Student" Then
Dim result As Integer = MessageBox.Show("Are you sure you want to add the student as a " & ComboBox1.Text, "Added", MessageBoxButtons.YesNo)
If result = DialogResult.Yes Then
Command.Connection = Connection
Command.CommandText = "UPDATE [Student] SET [Status] =@stat WHERE [RegistrationNumber] = '" & TextBox10.Text & "'"
Command.Parameters.AddWithValue("@stat", ComboBox1.Text)
Command.ExecuteNonQuery()
MsgBox("Student Status is " & ComboBox1.Text)
StudentRegister.loaded()
StudentRegister.Show()
Me.Hide()
ElseIf result = DialogResult.No Then
Me.Show()
End If
我不知道代码出了什么问题,(数据类型不匹配)请帮忙。谢谢。
答案 0 :(得分:0)
我已经多次遇到此错误,但是问题总是出在您传递的值与数据库中该表的数据类型不符
在这种情况下 Command.CommandText =“ UPDATE [学生] SET [状态] = @ stat WHERE [RegistrationNumber] ='”&TextBox10.Text&“'
RegistrationNumber可能是您数据库中的整数。
通过
Command.CommandText =“ UPDATE [学生] SET [状态] = @ stat WHERE [RegistrationNumber] = val('”&TextBox10.Text&“')”将起到神奇作用。祝你好运
答案 1 :(得分:0)
如果ComboBox1.Text =“新学生”则
Dim result As Integer = MessageBox.Show("Are you sure you want to add the student as a " & ComboBox1.Text, "Added", MessageBoxButtons.YesNo)
If result = DialogResult.Yes Then
Command.Connection = Connection
Command.CommandText = "UPDATE [Student] SET [Status] = '" & ComboBox1.Text & "' WHERE [RegistrationNumber] = '" & TextBox10.Text & "'"
Command.ExecuteNonQuery()
MsgBox("Student Status is " & ComboBox1.Text)
StudentRegister.loaded()
StudentRegister.Show()
Me.Hide()
ElseIf result = DialogResult.No Then
Me.Show()
End If
''我只是将ComboBox1.Text重定向到Command.CommandText而不是添加快捷方式:(@stat)