(08-09-20, 03:35 PM)momani33 كتب : شكرا للجميع تمت العمليه بنجاح ولكن عند محاولة عمل لووب في الداتا جريد فيو يظهر خطا عند تنفيذ الكود التالي :
Dim sql2 = "insert into invoice_list(invoice_number,store,Accounts_code,Accounts_name,item_code,item_name,item_count,item_price,item_descound,item_total,item_date,item_earn,item_catorgey,item_company,itembouns,tax_add,item_tax_add,new_count,item_group,item_balace)values(@invoice_number,@store,@Accounts_code,@Accounts_name,@item_code,@item_name,@item_count,@item_price,@item_descound,@item_total,@item_date,@item_earn,@item_catorgey,@item_company,@itembouns,@tax_add,@item_tax_add,@new_count,@item_group,@item_balace)"Dim cmd2 As New SqlCommand(sql2, sqlconn)
For i = 0 To dgv.Rows.Count - 1
cmd2.Parameters.AddWithValue("@invoice_number", invoice_number.Text)cmd2.Parameters.AddWithValue("@store", store.Text)cmd2.Parameters.AddWithValue("@Accounts_code", Accounts_code.Text)cmd2.Parameters.AddWithValue("@Accounts_name", Accounts_name.Text)
cmd2.Parameters.AddWithValue("@item_code", dgv.Rows(i).Cells(0).Value)cmd2.Parameters.AddWithValue("@item_name", dgv.Rows(i).Cells(1).Value)cmd2.Parameters.AddWithValue("@item_unit", dgv.Rows(i).Cells(2).Value)cmd2.Parameters.AddWithValue("@item_count", dgv.Rows(i).Cells(3).Value)cmd2.Parameters.AddWithValue("@item_price", dgv.Rows(i).Cells(4).Value)cmd2.Parameters.AddWithValue("@item_descound", dgv.Rows(i).Cells(5).Value)
cmd2.Parameters.AddWithValue("@item_total", dgv.Rows(i).Cells(6).Value)cmd2.Parameters.AddWithValue("@item_date", invoice_date.Value)cmd2.Parameters.AddWithValue("@item_earn", Convert.ToDecimal(dgv.Rows(i).Cells(8).Value))cmd2.Parameters.AddWithValue("@item_catorgey", dgv.Rows(i).Cells(9).Value)
cmd2.Parameters.AddWithValue("@item_company", dgv.Rows(i).Cells(10).Value)cmd2.Parameters.AddWithValue("@itembouns", dgv.Rows(i).Cells(11).Value)cmd2.Parameters.AddWithValue("@tax_add", dgv.Rows(i).Cells(12).Value)cmd2.Parameters.AddWithValue("@item_tax_add", dgv.Rows(i).Cells(13).Value)cmd2.Parameters.AddWithValue("@new_count", dgv.Rows(i).Cells(14).Value)cmd2.Parameters.AddWithValue("@item_group", dgv.Rows(i).Cells(15).Value)cmd2.Parameters.AddWithValue("@item_balace", dgv.Rows(i).Cells(16).Value)
'set_itemtrans(dgv.Rows(i).Cells(1).Value, invoice_date.Value, invoice_number.Text, "فاتورة مبيعات", 0, dgv.Rows(i).Cells(16).Value, dgv.Rows(i).Cells(14).Value)If sqlconn.State <> ConnectionState.Open Then sqlconn.Open()cmd2.ExecuteNonQuery()sqlconn.Close()Next
وضح انت بتعمل لووب ليه لان خطا انك تكرر رقم الفاتوره invoice_number
مش انت عاوز تحفظ فاتوره وحده بس؟؟
عموما هذا التعديل
PHP كود :
Dim sql2 = "insert into invoice_list(invoice_number,store,Accounts_code,Accounts_name,item_code,item_name,item_count,item_price,item_descound,item_total,item_date,item_earn,item_catorgey,item_company,itembouns,tax_add,item_tax_add,new_count,item_group,item_balace)values(@invoice_number,@store,@Accounts_code,@Accounts_name,@item_code,@item_name,@item_count,@item_price,@item_descound,@item_total,@item_date,@item_earn,@item_catorgey,@item_company,@itembouns,@tax_add,@item_tax_add,@new_count,@item_group,@item_balace)"
Dim cmd2 As New SqlCommand(sql2, sqlconn)
If sqlconn.State <> ConnectionState.Open Then sqlconn.Open()
For i = 0 To dgv.Rows.Count - 1
cmd2.Parameters.clear
cmd2.Parameters.AddWithValue("@invoice_number", invoice_number.Text)
cmd2.Parameters.AddWithValue("@store", store.Text)
cmd2.Parameters.AddWithValue("@Accounts_code", Accounts_code.Text)
cmd2.Parameters.AddWithValue("@Accounts_name", Accounts_name.Text)
cmd2.Parameters.AddWithValue("@item_code", dgv.Rows(i).Cells(0).Value)
cmd2.Parameters.AddWithValue("@item_name", dgv.Rows(i).Cells(1).Value)
cmd2.Parameters.AddWithValue("@item_unit", dgv.Rows(i).Cells(2).Value)
cmd2.Parameters.AddWithValue("@item_count", dgv.Rows(i).Cells(3).Value)
cmd2.Parameters.AddWithValue("@item_price", dgv.Rows(i).Cells(4).Value)
cmd2.Parameters.AddWithValue("@item_descound", dgv.Rows(i).Cells(5).Value)
cmd2.Parameters.AddWithValue("@item_total", dgv.Rows(i).Cells(6).Value)
cmd2.Parameters.AddWithValue("@item_date", invoice_date.Value)
cmd2.Parameters.AddWithValue("@item_earn", Convert.ToDecimal(dgv.Rows(i).Cells(8).Value))
cmd2.Parameters.AddWithValue("@item_catorgey", dgv.Rows(i).Cells(9).Value)
cmd2.Parameters.AddWithValue("@item_company", dgv.Rows(i).Cells(10).Value)
cmd2.Parameters.AddWithValue("@itembouns", dgv.Rows(i).Cells(11).Value)
cmd2.Parameters.AddWithValue("@tax_add", dgv.Rows(i).Cells(12).Value)
cmd2.Parameters.AddWithValue("@item_tax_add", dgv.Rows(i).Cells(13).Value)
cmd2.Parameters.AddWithValue("@new_count", dgv.Rows(i).Cells(14).Value)
cmd2.Parameters.AddWithValue("@item_group", dgv.Rows(i).Cells(15).Value)
cmd2.Parameters.AddWithValue("@item_balace", dgv.Rows(i).Cells(16).Value)
'set_itemtrans(dgv.Rows(i).Cells(1).Value, invoice_date.Value, invoice_number.Text, "فاتورة مبيعات", 0, dgv.Rows(i).Cells(16).Value, dgv.Rows(i).Cells(14).Value)
cmd2.ExecuteNonQuery()
Next
sqlconn.Close()
