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

نسخة كاملة : لا جديد الا في كود البحث(محاولة ايجاد اقصر كود للحفظ)
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
السطر التالي يطلب تنفيذ اجرائين لتحديد الصف والحقل
اضافة الى اشياء اخرى معروفة تكمل بعضها اضفتها ليكتمل المثال
الموجود اكواد الاضافة والتحرير او التحديث فقط
PHP كود :
       dg.CurrentCell dg.Rows(trowindex(txtsearch.Text)).Cells(cellindex(txtsearch.Text)) 
اضفت زر للملف السابق وبه الكود التالي اللذي لم ينجح ولم افهم لماذا:
PHP كود :
Using cm As New OleDb.OleDbCommand(""con)
 
           cm.CommandText "insert into tb(tname,bd,temail,homephone,mobile,country,sex,fav

car,hob) values(@tname,@bd,@temail,@homephone,@mobile,@country,@sex,@favcar,@hob)"
 
           For Each h As Control In Panel1.Controls
                If TypeOf h Is DateTimePicker Then
                    cm
.Parameters.AddWithValue("@" CType(hDateTimePicker).Name ""CType(hDateTimePicker).Value)
 
               ElseIf TypeOf h Is TextBox Then
                    cm
.Parameters.AddWithValue("@" CType(hTextBox).Name ""CType(hTextBox).Text)
 
               ElseIf TypeOf h Is ComboBox Then
                    cm
.Parameters.AddWithValue("@" CType(hComboBox).Name ""CType(hComboBox).Text)
 
               End If
 
           Next
            Try
                If con
.State ConnectionState.Closed Then con.Open()
 
               cm.ExecuteNonQuery()
 
               gd(dg.Rows.Count IIf(dg.AllowUserToAddRows21))
 
               If con.State ConnectionState.Open Then con.Close()
 
           Catch ex As Exception
                MsgBox
(Err.DescriptionMsgBoxStyle.Critical"error")
 
           End Try
 
       End Using 


فكرتي من الكود ان اختصر كتابة الاكواد بحيث يمر على كافة العناصر او الادوات اللتي موجودة ضمن Panel1  ..........انظروا للكود ورسالة الخطا اختلاف تعبير المعايير
عرفت الخطا وهو مسالة ترتيب البارامترات فلا اعرف كيف ارتبها لان الادوات لا تاتي مرتبة
(10-03-23, 08:00 PM)سعود كتب : [ -> ]اضفت زر للملف السابق وبه الكود التالي اللذي لم ينجح ولم افهم لماذا:
PHP كود :
Using cm As New OleDb.OleDbCommand(""con)
 
           cm.CommandText "insert into tb(tname,bd,temail,homephone,mobile,country,sex,fav

car,hob) values(@tname,@bd,@temail,@homephone,@mobile,@country,@sex,@favcar,@hob)"
 
           For Each h As Control In Panel1.Controls
                If TypeOf h Is DateTimePicker Then
                    cm
.Parameters.AddWithValue("@" CType(hDateTimePicker).Name ""CType(hDateTimePicker).Value)
 
               ElseIf TypeOf h Is TextBox Then
                    cm
.Parameters.AddWithValue("@" CType(hTextBox).Name ""CType(hTextBox).Text)
 
               ElseIf TypeOf h Is ComboBox Then
                    cm
.Parameters.AddWithValue("@" CType(hComboBox).Name ""CType(hComboBox).Text)
 
               End If
 
           Next
            Try
                If con
.State ConnectionState.Closed Then con.Open()
 
               cm.ExecuteNonQuery()
 
               gd(dg.Rows.Count IIf(dg.AllowUserToAddRows21))
 
               If con.State ConnectionState.Open Then con.Close()
 
           Catch ex As Exception
                MsgBox
(Err.DescriptionMsgBoxStyle.Critical"error")
 
           End Try
 
       End Using 


فكرتي من الكود ان اختصر كتابة الاكواد بحيث يمر على كافة العناصر او الادوات اللتي موجودة ضمن Panel1  ..........انظروا للكود ورسالة الخطا اختلاف تعبير المعايير
عرفت الخطا وهو مسالة ترتيب البارامترات فلا اعلاف كيف ارتبها لان الادوات لا تاتي مرتبة

بالأمس واجهتني نفس المشكلة وبجهد جهيد استطعت أن اتتبع ترتيب البارامترات حتى حللت المشكلة
نجحت بعد كم خطوة نفذتها ومادام تعبت بهالخطوات هذي اجل ما الفائدة منها؟Smile
لان قصدي تنفيذ اكبر عدد من الاسطر بالمتغيرات:


الخطوة الاولى: 1
PHP كود :
   Dim mycontrols As New List(Of Control


 2 in Form_Load event
 
PHP كود :
       mycontrols.Add(tname)
 
       mycontrols.Add(bd)
 
       mycontrols.Add(temail)
 
       mycontrols.Add(homephone)
 
       mycontrols.Add(mobile)
 
       mycontrols.Add(country)
 
       mycontrols.Add(sex)
 
       mycontrols.Add(favcar)
 
       mycontrols.Add(hob

الخطوة الاخيرة 3
PHP كود :
Using cm As New OleDb.OleDbCommand(""con)
 
           cm.CommandText "insert into tb(tname,bd,temail,homephone,mobile,country,sex,favcar,hob) values(@tname,@bd,@temail,@homephone,@mobile,@country,@sex,@favcar,@hob)"
 
           For Each h As Control In mycontrols
                If TypeOf h Is DateTimePicker Then
                    cm
.Parameters.AddWithValue("@" CType(hDateTimePicker).Name ""CType(hDateTimePicker).Value.ToShortDateString)
 
               ElseIf TypeOf h Is TextBox Then
                    cm
.Parameters.AddWithValue("@" CType(hTextBox).Name ""IIf(IsNumeric(CType(hTextBox).Text), Val(CType(hTextBox).Text), CType(hTextBox).Text))
 
               ElseIf TypeOf h Is ComboBox Then
                    cm
.Parameters.AddWithValue("@" CType(hComboBox).Name ""CType(hComboBox).Text)
 
               End If
 
           Next
            Try
                If con
.State ConnectionState.Closed Then con.Open()
 
               cm.ExecuteNonQuery()
 
               gd(dg.Rows.Count IIf(dg.AllowUserToAddRows21))
 
               If con.State ConnectionState.Open Then con.Close()
 
           Catch ex As Exception
                MsgBox
(Err.DescriptionMsgBoxStyle.Critical"error")
 
           End Try
 
       End Using 

رتبت البارمترات كما تظهر من عناصر البانل::
PHP كود :
Using cm As New OleDb.OleDbCommand(""con)
 
           cm.CommandText "insert into tb(tname,hob,bd,favcar,temail,sex,homephone,country,mobile) values(@tname,@hob,@bd,@favcar,@temail,@sex,@homephone,@country,@mobile)"
 
           For Each h As Control In Panel1.Controls
                If TypeOf h Is DateTimePicker Then
                    cm
.Parameters.AddWithValue("@" CType(hDateTimePicker).Name ""CType(hDateTimePicker).Value.ToShortDateString)
 
               ElseIf TypeOf h Is TextBox Then
                    cm
.Parameters.AddWithValue("@" CType(hTextBox).Name ""IIf(IsNumeric(CType(hTextBox).Text), Val(CType(hTextBox).Text), CType(hTextBox).Text))
 
               ElseIf TypeOf h Is ComboBox Then
                    cm
.Parameters.AddWithValue("@" CType(hComboBox).Name ""CType(hComboBox).Text)
 
               End If
 
           Next

            Try
                If con
.State ConnectionState.Closed Then con.Open()
 
               cm.ExecuteNonQuery()
 
               gd(dg.Rows.Count IIf(dg.AllowUserToAddRows10))
 
               If con.State ConnectionState.Open Then con.Close()
 
           Catch ex As Exception
                MsgBox
(Err.DescriptionMsgBoxStyle.Critical"error")
 
           End Try
 
       End Using 

المطلوب اقصر من كذا!!!
هل تظنون استخدام الـDataRow للاضافة قد توفر امكانية تقصير الاكواد؟!
اذا شاء الله ساجرب.
لم اجد افضل مما وجدتSmile
فقط حدثت باضافة بعض ازرار التصفح
ضغط وضبط او الغاء كلمة مرور لملف القاعدة _ وانظر كيف تكون تسميات للملف القديم مرقمة