sql 插入不工作 vb.net 2012

sql insert not working vb.net 2012

我正在尽力将记录插入数据库。我没有添加记录,也没有显示一些错误。请帮我。我在 Visual studio 2012.

中使用 localdb
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

CommandText 没有与您要添加的参数名称匹配的参数。相反,您已经硬编码

VALUES ('Ana', '2', '2', '2', 'Both' )

相反,尝试:

VALUES (@tax_catagory, @tax_rate, @ed_cess_rate, @s_ed_cess_rate, @tax_on)