作爲Vb noob即時通訊工作在這個學校項目。我需要插入我的值到我的MySQL數據庫,但由於它沒有插入嘗試的一切,但我找不到爲什麼它不插入。 THX提前VB插入MySql
Dim sqlCommand As New MySqlCommand
Dim SQLConnection As MySqlConnection = New MySqlConnection
Dim strStockSQL As String
Dim server As String = "localhost"
Dim DatabaseName As String = "Gip"
Dim userName As String = "root"
Dim password As String = ""
SQLConnection = New MySqlConnection()
If Not conn Is Nothing Then conn.Close()
conn.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false", server, userName, password, DatabaseName)
Try
strStockSQL = "insert into stock (Barcode,Naam_Product,Verkoopprijs) values (@Barcode,@Naam_product,@Verkoopprijs)"
sqlCommand.Connection = SQLConnection
sqlCommand.CommandText = strStockSQL
sqlCommand.Parameters.AddWithValue("@Barcode", Convert.ToString(txtBarcode.Text))
sqlCommand.Parameters.AddWithValue("@Naam_product", Convert.ToString(txtNaam.Text))
sqlCommand.Parameters.AddWithValue("@Verkoopprijs", Convert.ToInt32(txtVP.Text))
sqlCommand.ExecuteNonQuery()
Catch ex As Exception
MsgBox("Error occured: Could not insert record")
是否應該有某個地方的問題? – specializt
是否發生異常?如果是,那麼請讓我們知道它是什麼。 –
不,我沒有得到vb的錯誤。它只是我的Try Catch告訴我錄製的內容不能被插入。 – Nordin