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
Open in new window