21-12-17, 10:08 AM
Dim CmdInsert As New SqlCommand
With CmdInsert
.Connection = Con
.CommandType = CommandType.Text
.CommandText = "Insert Into store_id (num , date , mowared , senfnum , q1 , q2 , price , currencey , currenceyrate , stornum)values( @num , @date , @mowared , @senfnum , @q1 , @q2 , @price , @currencey , @currenceyrate , @stornum)"
.Parameters.Clear()
For i As Integer = 0 To (DataGridView1.Rows.Count - 1)
.Parameters.AddWithValue("@num", SqlDbType.Int).Value = Val(TextBox1.Text)
.Parameters.AddWithValue("@date", SqlDbType.Date).Value = Dtpdate.Value
.Parameters.AddWithValue("@mowared", SqlDbType.Int).Value = Val(TextBox2.Text)
.Parameters.AddWithValue("@senfnum", SqlDbType.Int).Value = DataGridView1(0, i).Value.ToString
.Parameters.AddWithValue("@q1", SqlDbType.Decimal).Value = DataGridView1(2, i).Value.ToString
.Parameters.AddWithValue("@q2", SqlDbType.Decimal).Value = DataGridView1(3, i).Value.ToString
.Parameters.AddWithValue("@price", SqlDbType.Decimal).Value = DataGridView1(6, i).Value.ToString
.Parameters.AddWithValue("@currencey", SqlDbType.Int).Value = Val(TextBox9.Text)
.Parameters.AddWithValue("@currenceyrate", SqlDbType.Decimal).Value = Val(TextBox10.Text)
.Parameters.AddWithValue("@stornum", SqlDbType.Int).Value = DataGridView1(4, i).Value.ToString
Next
' Try
If Con.State = 1 Then Con.Close()
Con.Open()
CmdInsert.ExecuteNonQuery()
Con.Close()
MsgBox("تم إضافة السجل بنجاح", MsgBoxStyle.Information, "حفظ")
CmdInsert = Nothing
' Catch ex As Exception
' 'Con.Close()
' MsgBox(Err.Description, MsgBoxStyle.Information)
' Finally
If Con.State = ConnectionState.Open Then Con.Close()
End With
' End Try
الخطا الذي يخرج يقول
The variable name '@num' has already been declared. Variable names must be unique within a query batch or stored procedure.
With CmdInsert
.Connection = Con
.CommandType = CommandType.Text
.CommandText = "Insert Into store_id (num , date , mowared , senfnum , q1 , q2 , price , currencey , currenceyrate , stornum)values( @num , @date , @mowared , @senfnum , @q1 , @q2 , @price , @currencey , @currenceyrate , @stornum)"
.Parameters.Clear()
For i As Integer = 0 To (DataGridView1.Rows.Count - 1)
.Parameters.AddWithValue("@num", SqlDbType.Int).Value = Val(TextBox1.Text)
.Parameters.AddWithValue("@date", SqlDbType.Date).Value = Dtpdate.Value
.Parameters.AddWithValue("@mowared", SqlDbType.Int).Value = Val(TextBox2.Text)
.Parameters.AddWithValue("@senfnum", SqlDbType.Int).Value = DataGridView1(0, i).Value.ToString
.Parameters.AddWithValue("@q1", SqlDbType.Decimal).Value = DataGridView1(2, i).Value.ToString
.Parameters.AddWithValue("@q2", SqlDbType.Decimal).Value = DataGridView1(3, i).Value.ToString
.Parameters.AddWithValue("@price", SqlDbType.Decimal).Value = DataGridView1(6, i).Value.ToString
.Parameters.AddWithValue("@currencey", SqlDbType.Int).Value = Val(TextBox9.Text)
.Parameters.AddWithValue("@currenceyrate", SqlDbType.Decimal).Value = Val(TextBox10.Text)
.Parameters.AddWithValue("@stornum", SqlDbType.Int).Value = DataGridView1(4, i).Value.ToString
Next
' Try
If Con.State = 1 Then Con.Close()
Con.Open()
CmdInsert.ExecuteNonQuery()
Con.Close()
MsgBox("تم إضافة السجل بنجاح", MsgBoxStyle.Information, "حفظ")
CmdInsert = Nothing
' Catch ex As Exception
' 'Con.Close()
' MsgBox(Err.Description, MsgBoxStyle.Information)
' Finally
If Con.State = ConnectionState.Open Then Con.Close()
End With
' End Try
الخطا الذي يخرج يقول
The variable name '@num' has already been declared. Variable names must be unique within a query batch or stored procedure.