-2
我正在盡我所能將記錄插入數據庫。我沒有得到添加的記錄,也沒有顯示一些錯誤。請幫幫我。我在Visual Studio 2012中使用localdb。sql插入不工作vb.net 2012
Imports System.Data.SqlClient
Imports System.Data
Public Class tax_configure
Private Sub tax_configure_Load(sender As Object, e As EventArgs) Handles MyBase.Load
With tax_on_combo
.SelectedIndex = 0
End With
End Sub
Private Sub add_tax_cata_Click(sender As Object, e As EventArgs) Handles add_tax_cata.Click
Dim con As New SqlConnection
Dim com As New SqlCommand
Try
con.ConnectionString = "Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\My VB projects\Test App\Test App\bin\Debug\test_db.mdf;Integrated Security=True;Connect Timeout=30"
con.Open()
com.Connection = con
com.CommandText = "INSERT INTO [dbo].[tax_details] ([tax_catagory], [tax_rate], [ed_cess_rate], [s_ed_cess_rate], [tax_on]) VALUES (@tax_catagory, @tax_rate, @ed_cess_rate, @s_ed_cess_rate, @tax_on)"
com.Parameters.Add(New SqlParameter("@tax_catagory", tax_cata_name.Text))
com.Parameters.Add(New SqlParameter("@tax_rate", Val(tax_rate_txt.Text)))
com.Parameters.Add(New SqlParameter("@ed_cess_rate", Val(Ecess_rate_txt.Text)))
com.Parameters.Add(New SqlParameter("@s_ed_cess_rate", Val(SEcess_rate_txt.Text)))
com.Parameters.Add(New SqlParameter("@tax_on", tax_on_combo.SelectedText))
com.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
con.Close()
End Try
End Sub
End Class
如果你不能打擾告訴我們什麼「一些錯誤」是,我們要猜測的解決方案?你不應該使用'Val'它只返回Double,它可能與DB中的類型不匹配,如果用戶輸入「I Like Pie」作爲稅率,它也會崩潰 – Plutonix
您是在問我們如何閱讀錯誤信息?這就像讀別的東西。你看看它,把字符分組成單詞,把單詞分成單詞,等等。 – David
另外,你正在嘗試向一個沒有任何查詢的查詢添加參數。 – David