troubleshooting Question

SQL Insert and Update Commands in vb.net

Avatar of arozzy
arozzy asked on
Microsoft SQL Server.NET Programming
11 Comments1 Solution594 ViewsLast Modified:
Hi Experts,

I have some trouble with sql commands in VB.net,  

On a winform, I am trying to insert new data to Ms sql database table, each data has its own text.box areas.

my codes,

    Dim adptr2 As New SqlDataAdapter("select * from  STOKANA", baglan)
    Dim stkekle As New SqlCommand("insert into STOKANA values(@SN,@SA,@SM,@SB,@EM,@RD)", baglan)
    Dim ds1 As New DataSet


button click event
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If TextBox1.Text = "" Then
            MessageBox.Show("Stok adi giriniz.", "STOK ADI", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            TextBox1.Focus()
        ElseIf TextBox2.Text = "" Then
            MessageBox.Show("Stok miktarini giriniz.", "STOK MIKTARI", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            TextBox2.Focus()
        ElseIf ComboBox1.Text = "" Then
            MessageBox.Show("Stok birimini giriniz.", "STOK BIRIMI", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            TextBox2.Focus()
        ElseIf TextBox4.Text = "" Then
            MessageBox.Show("Stok miktarini giriniz.", "STOK MIKTARI", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            TextBox4.Focus()
        Else

            Try
                stkekle.Parameters.AddWithValue("SN", TextBox10.Text)
                stkekle.Parameters.AddWithValue("SA", TextBox1.Text)
                stkekle.Parameters.AddWithValue("SM", TextBox2.Text)
                stkekle.Parameters.AddWithValue("SB", ComboBox1.Text)
                stkekle.Parameters.AddWithValue("EM", TextBox4.Text)
                stkekle.Parameters.AddWithValue("RD", CheckBox1.CheckState)
                baglan.Open()
                adptr2.InsertCommand = stkekle
                stkekle.ExecuteNonQuery()
                MsgBox("Kayit eklendi !!")
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            baglan.Close()
            Call veri1()
            End If
    End Sub

after adding first data row on sql table, I could not add second data row  and the error massage is that "sql data sqlcient sql expection (0x80131904). The variable name '@SN' has already been declared.  


The update command

I am using datagrid to show user which data he wanna update and data is going to on  textboxes and checkboxes on the form by clicking on selected datagird row object.
when updating the data,  the error massage is that sql data sqlcient sql expection (0x80131904). Error converting data type nvarchar to numeric.

Please help

Thank you

Oguzhan
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 11 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros