每次嘗試向我的數據庫表中添加信息時,都會產生錯誤。將信息添加到數據庫時出現System.ArgumentException
Error: An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll
Additional information: Input string was not in a correct format.Couldn't store <JHK> in KEY TAG Column. Expected type is Int32.
這是我的代碼到目前爲止。
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class add_new_key_window
Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub add_new_key_window_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'saveRecord()
management_window.RKM_SystemTableAdapter.Insert(Me.TextBox1.Text, Me.TextBox2.Text, Me.TextBox3.Text, Me.TextBox4.Text, Me.TextBox5.Text, Me.TextBox6.Text, Me.RichTextBox1.Text)
management_window.RKM_SystemTableAdapter.Fill(management_window.RKM_System_dataDataSet.RKM_System)
clearTextboxes()
End Sub
'Public Sub saveRecord()
' Dim cn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data source=" & Application.StartupPath & "\RKM System data.accdb")
' Dim str As String
' Try
' cn.Open()
' Dim cmd As New System.Data.OleDb.OleDbCommand("INSERT INTO [RKM System]([KEY TAG], LOCATION, [HOOK NO], [KEY TYPE], BRAND, SERIAL, [TAG COLOR], NOTES) " & _
' "VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "','1','" & TextBox3.Text & _
' "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & _
' "','" & RichTextBox1.Text & "') ", cn)
' str = cmd.ExecuteNonQuery
' MsgBox("The new record was inserted successfully!")
' Catch ex As Exception
' MsgBox("Error message: " & ex.Message)
' End Try
' cn.Close()
'End Sub
Public Sub clearTextboxes()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
RichTextBox1.Clear()
End Sub
End Class
Int.TryParse是你的朋友... –
冬青牛...我忘了提及...我是一個非常初學者。我知道需要解釋很多,但我對編碼充滿激情,我想學習。有沒有解釋的機會,你會向初學者解釋?非常感謝你快速回來。 – Kobra
在關於語法錯誤的問題流向你之前,你可能想現在把它轉換成VB。另外,您要添加兩次TB1,而OleDb實際上並不使用可能會引起誤解的命名參數。 – Plutonix