vb.net和ms access上的数据类型不匹配
我不知道代码有什么问题,(数据类型不匹配)请帮助。谢谢。我多次遇到此错误,但问题总是来自您传递的值,而不是与数据库中该表的数据类型对应的值 在这种情况下 Command.CommandText=“更新[Student]设置[Status]=@stat其中[RegistrationNumber]=”&TextBox10.Text&“' RegistrationNumber可能是数据库中的整数 将其作为 Command.CommandText=“UPDATE[Student]SET[Status]=@stat其中[RegistrationNumber]=val(“”&TextBox10.Text&“”)将起到神奇的作用。祝你好运vb.net和ms access上的数据类型不匹配,vb.net,Vb.net,我不知道代码有什么问题,(数据类型不匹配)请帮助。谢谢。我多次遇到此错误,但问题总是来自您传递的值,而不是与数据库中该表的数据类型对应的值 在这种情况下 Command.CommandText=“更新[Student]设置[Status]=@stat其中[RegistrationNumber]=”&TextBox10.Text&“' RegistrationNumber可能是数据库中的整数 将其作为 Command.CommandText=“UPDATE[Student]SET[Status]=
''我只是将ComboBox1.Text重定向到Command.CommandText,而不是添加快捷方式:(@stat)数据库中Status和RegistrationNumber字段的数据类型是什么?您在此处传递两个字符串。您还可以解释为什么一个字段使用参数,另一个字段使用字符串连接吗?使用always Parameters很可能是这样的:
其中[RegistrationNumber]='“&TextBox10.Text&'”
如果RegistrationNumber是*号,则将值作为文本传递。如前所述,始终使用SQL参数在代码的哪一行标记该错误?非常感谢。我已经纠正了错误
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
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