10-03-23, 08:00 PM (آخر تعديل لهذه المشاركة : 14-03-23, 02:04 PM {2} بواسطة سعود.)
اضفت زر للملف السابق وبه الكود التالي اللذي لم ينجح ولم افهم لماذا:
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(h, DateTimePicker).Name & "", CType(h, DateTimePicker).Value) ElseIf TypeOf h Is TextBox Then cm.Parameters.AddWithValue("@" & CType(h, TextBox).Name & "", CType(h, TextBox).Text) ElseIf TypeOf h Is ComboBox Then cm.Parameters.AddWithValue("@" & CType(h, ComboBox).Name & "", CType(h, ComboBox).Text) End If Next Try If con.State = ConnectionState.Closed Then con.Open() cm.ExecuteNonQuery() gd(dg.Rows.Count - IIf(dg.AllowUserToAddRows, 2, 1)) If con.State = ConnectionState.Open Then con.Close() Catch ex As Exception MsgBox(Err.Description, MsgBoxStyle.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(h, DateTimePicker).Name & "", CType(h, DateTimePicker).Value) ElseIf TypeOf h Is TextBox Then cm.Parameters.AddWithValue("@" & CType(h, TextBox).Name & "", CType(h, TextBox).Text) ElseIf TypeOf h Is ComboBox Then cm.Parameters.AddWithValue("@" & CType(h, ComboBox).Name & "", CType(h, ComboBox).Text) End If Next Try If con.State = ConnectionState.Closed Then con.Open() cm.ExecuteNonQuery() gd(dg.Rows.Count - IIf(dg.AllowUserToAddRows, 2, 1)) If con.State = ConnectionState.Open Then con.Close() Catch ex As Exception MsgBox(Err.Description, MsgBoxStyle.Critical, "error") End Try End Using
فكرتي من الكود ان اختصر كتابة الاكواد بحيث يمر على كافة العناصر او الادوات اللتي موجودة ضمن Panel1 ..........انظروا للكود ورسالة الخطا اختلاف تعبير المعايير
عرفت الخطا وهو مسالة ترتيب البارامترات فلا اعلاف كيف ارتبها لان الادوات لا تاتي مرتبة
بالأمس واجهتني نفس المشكلة وبجهد جهيد استطعت أن اتتبع ترتيب البارامترات حتى حللت المشكلة
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(h, DateTimePicker).Name & "", CType(h, DateTimePicker).Value.ToShortDateString) ElseIf TypeOf h Is TextBox Then cm.Parameters.AddWithValue("@" & CType(h, TextBox).Name & "", IIf(IsNumeric(CType(h, TextBox).Text), Val(CType(h, TextBox).Text), CType(h, TextBox).Text)) ElseIf TypeOf h Is ComboBox Then cm.Parameters.AddWithValue("@" & CType(h, ComboBox).Name & "", CType(h, ComboBox).Text) End If Next Try If con.State = ConnectionState.Closed Then con.Open() cm.ExecuteNonQuery() gd(dg.Rows.Count - IIf(dg.AllowUserToAddRows, 2, 1)) If con.State = ConnectionState.Open Then con.Close() Catch ex As Exception MsgBox(Err.Description, MsgBoxStyle.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(h, DateTimePicker).Name & "", CType(h, DateTimePicker).Value.ToShortDateString) ElseIf TypeOf h Is TextBox Then cm.Parameters.AddWithValue("@" & CType(h, TextBox).Name & "", IIf(IsNumeric(CType(h, TextBox).Text), Val(CType(h, TextBox).Text), CType(h, TextBox).Text)) ElseIf TypeOf h Is ComboBox Then cm.Parameters.AddWithValue("@" & CType(h, ComboBox).Name & "", CType(h, ComboBox).Text) End If Next
Try If con.State = ConnectionState.Closed Then con.Open() cm.ExecuteNonQuery() gd(dg.Rows.Count - IIf(dg.AllowUserToAddRows, 1, 0)) If con.State = ConnectionState.Open Then con.Close() Catch ex As Exception MsgBox(Err.Description, MsgBoxStyle.Critical, "error") End Try End Using
المطلوب اقصر من كذا!!!
هل تظنون استخدام الـDataRow للاضافة قد توفر امكانية تقصير الاكواد؟!
اذا شاء الله ساجرب. لم اجد افضل مما وجدت