منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : مشكلة عند حفظ البيانات في قاعدة بيانات SQL Server
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
السلام عليكم : لدي مشكلة  عند الضغط على زر الحفظ وتتلخص المشكلة ان البرنامج يتحاج حوالي 40 ثانية لحفظ البيانات حيث ان الجدول يحتوي على 25 الف سجل  عندما كانت السجلات قليلة كانت الامور تمام  ما الحل ؟؟؟؟؟؟
كود حفظ السجل :
  Dim sql = "select * from invoice_add where invoice_number=N'" & (invoice_number.Text) & "'"
        Dim adp As New SqlDataAdapter(sql, sqlconn)
        Dim ds As New DataSet
        adp.Fill(ds)
        Dim dt = ds.Tables(0)
        If dt.Rows.Count > 0 Then
        Else
            Dim dr = dt.NewRow
            dr!invoice_number = invoice_number.Text
            dr!store = store.Text
            dr!invoice_date = invoice_date.Value

            dr!Accounts_name = Accounts_name.Text
            dr!Accounts_code = Accounts_code.Text
            dr!invoice_note = ""
            dr!invoice_descound = invoice_descound.Text
            dr!invoice_tax = 0
            dr!invoice_count = invoice_count.Text
            dr!total_invoice = total_invoice.Text
            dr!delegate_name = ""
            dr!type_pay = type_pay.Text
            dr!Shipping_company = ""
            dr!earn_invoice = earn_invoice.Text
            dr!Cuscusgroup = Cuscusgroup.Text
            dr!cusGovernorate = cusGovernorate.Text
            dr!cuscity = cuscity.Text
            dr!pay_money = pay_money.Text
            dr!code_print = 1
            dr!user_invoice = user_name.Text
            dr!total_string = amount_string.Text
            dr!invoice_pound = invoice_pound.Text
            dr!pay = pay_money.Text
            dr!new_balace = new_balace.Text
            dr!Accounts_adress = ""
            dr!Accounts_phone1 = ""
            dr!past_balace = Accounts_balace.Text
            dr!money_plus = money_plus.Text
وعليكم السلام ورحمة الله
من الطبيعي ذلك وايضاً الوقت هيتكاثر اكثر فاكثر مع مرور الوقت
وهو انك تقوم بجلب جميع ما بداخل الجدول من خلال البحث عن طريق نص
بخصوص هنا
invoice_number=N
تاكد بان invoice_number من نوع رقم وليس نص لان بوجود N هذا يشير بان العمود نصي وليس رقمي
ومن الممكن انك قمت بعمل نصي لكون الارقام قد تبداء بـ 0 او تتجاوز الـ 9 ارقام فهناك حلول اخري لذلك
(07-09-20, 09:14 PM)momani33 كتب : [ -> ]السلام عليكم : لدي مشكلة  عند الضغط على زر الحفظ وتتلخص المشكلة ان البرنامج يتحاج حوالي 40 ثانية لحفظ البيانات حيث ان الجدول يحتوي على 25 الف سجل  عندما كانت السجلات قليلة كانت الامور تمام  ما الحل ؟؟؟؟؟؟
كود حفظ السجل :
  Dim sql = "select * from invoice_add where invoice_number=N'" & (invoice_number.Text) & "'"
        Dim adp As New SqlDataAdapter(sql, sqlconn)
        Dim ds As New DataSet
        adp.Fill(ds)
        Dim dt = ds.Tables(0)
        If dt.Rows.Count > 0 Then
        Else
            Dim dr = dt.NewRow
            dr!invoice_number = invoice_number.Text
            dr!store = store.Text
            dr!invoice_date = invoice_date.Value

            dr!Accounts_name = Accounts_name.Text
            dr!Accounts_code = Accounts_code.Text
            dr!invoice_note = ""
            dr!invoice_descound = invoice_descound.Text
            dr!invoice_tax = 0
            dr!invoice_count = invoice_count.Text
            dr!total_invoice = total_invoice.Text
            dr!delegate_name = ""
            dr!type_pay = type_pay.Text
            dr!Shipping_company = ""
            dr!earn_invoice = earn_invoice.Text
            dr!Cuscusgroup = Cuscusgroup.Text
            dr!cusGovernorate = cusGovernorate.Text
            dr!cuscity = cuscity.Text
            dr!pay_money = pay_money.Text
            dr!code_print = 1
            dr!user_invoice = user_name.Text
            dr!total_string = amount_string.Text
            dr!invoice_pound = invoice_pound.Text
            dr!pay = pay_money.Text
            dr!new_balace = new_balace.Text
            dr!Accounts_adress = ""
            dr!Accounts_phone1 = ""
            dr!past_balace = Accounts_balace.Text
            dr!money_plus = money_plus.Text

مثل ما قال اخي kiki انت بتجلب كل ما بداخل الجدول
كمان انت بتستخدم اسلوب قديم جدا

where للتحديث او الاستعلام
انت وضعت NewRow يعني بتقصد اضافه جديد فما داعي الى where
هذا هو اسلوب الدوت نت
PHP كود :
Dim sql "insert into invoice_add(invoice_number,store,invoice_date,Accounts_name,Accounts_code,invoice_note,invoice_descound,invoice_tax,invoice_count,total_invoice,delegate_name,type_pay,Shipping_company,earn_invoice,Cuscusgroup,cusGovernorate,cuscity,pay_money,code_print,user_invoice,total_string,invoice_pound,pay,new_balace,Accounts_adress,Accounts_phone1,past_balace,money_plus) values(@invoice_number,@store,@invoice_date,@Accounts_name,@Accounts_code,@invoice_note,@invoice_descound,@invoice_tax,@invoice_count,@total_invoice,@delegate_name,@type_pay,@Shipping_company,@earn_invoice,@Cuscusgroup,@cusGovernorate,@cuscity,@pay_money,@code_print,@user_invoice,@total_string,@invoice_pound,@pay,@new_balace,@Accounts_adress,@Accounts_phone1,@past_balace,@money_plus)"
Dim cmd As New SqlCommand(sqlsqlconn)
cmd.Parameters.AddWithValue("@invoice_number"invoice_number.Text)
cmd.Parameters.AddWithValue("@store"store.Text)
cmd.Parameters.AddWithValue("@invoice_date"invoice_date.Value)
cmd.Parameters.AddWithValue("@Accounts_name"Accounts_name.Text)
cmd.Parameters.AddWithValue("@Accounts_code"Accounts_code.Text)
cmd.Parameters.AddWithValue("@invoice_note""")
cmd.Parameters.AddWithValue("@invoice_descound"invoice_descound.Text)
cmd.Parameters.AddWithValue("@invoice_tax"0)
cmd.Parameters.AddWithValue("@invoice_count"invoice_count.Text)
cmd.Parameters.AddWithValue("@total_invoice"total_invoice.Text)
cmd.Parameters.AddWithValue("@delegate_name""")
cmd.Parameters.AddWithValue("@type_pay"type_pay.Text)
cmd.Parameters.AddWithValue("@Shipping_company""")
cmd.Parameters.AddWithValue("@earn_invoice"earn_invoice.Text)
cmd.Parameters.AddWithValue("@Cuscusgroup"Cuscusgroup.Text)
cmd.Parameters.AddWithValue("@cusGovernorate"cusGovernorate.Text)
cmd.Parameters.AddWithValue("@cuscity"cuscity.Text)
cmd.Parameters.AddWithValue("@pay_money"pay_money.Text)
cmd.Parameters.AddWithValue("@code_print"1)
cmd.Parameters.AddWithValue("@user_invoice"user_name.Text)
cmd.Parameters.AddWithValue("@total_string"amount_string.Text)
cmd.Parameters.AddWithValue("@invoice_pound"invoice_pound.Text)
cmd.Parameters.AddWithValue("@pay"pay_money.Text)
cmd.Parameters.AddWithValue("@new_balace"new_balace.Text)
cmd.Parameters.AddWithValue("@Accounts_adress""")
cmd.Parameters.AddWithValue("@Accounts_phone1""")
cmd.Parameters.AddWithValue("@past_balace"Accounts_balace.Text)
cmd.Parameters.AddWithValue("@money_plus"money_plus.Text)

If 
sqlconn.State <> ConnectionState.Open Then sqlconn.Open()
cmd.ExecuteNonQuery()
sqlconn.Close() 
شكرا للجميع تمت العمليه بنجاح ولكن عند محاولة عمل لووب في  الداتا جريد فيو يظهر خطا عند تنفيذ الكود التالي :
 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
(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(sql2sqlconn)

 
      
            If sqlconn
.State <> ConnectionState.Open Then sqlconn.Open()

For 
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()