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

نسخة كاملة : مشكلة مع زر اضافة سجل
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
الصفحات : 1 2
هذا هو السورس كود لحفظ سجل عندى والادوات الموجوده على الفورم
3 تيكست بوكس وريتش بوكس

إقتباس :If TextBox1.Text = vbNullString Then
MessageBox.Show("أنت لم تدخــــل الأســــــم", "تنبيـــه", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)

PhoneFrm_Load(Nothing, Nothing)
Exit Sub
End If

Dim GetHim As New OleDbDataAdapter("Select * from tabel2 Where Nam='" & TextBox1.Text & "'", Cn)
Dim DS1 As New DataSet
DS1.Clear()
GetHim.Fill(DS1, "tabel2")
If DS1.Tables("tabel2").Rows.Count <> 0 Then
MessageBox.Show("موجـــــــود ســــــابقا", "تنبيـــــــه", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
PhoneFrm_Load(Nothing, Nothing)
Exit Sub
End If

'======================================
Try
NewBtn.Enabled = False

BS.EndEdit()

DP.Update(DS, "tabel2")

DS.Clear()

DP.Fill(DS, "tabel2")

BS.MoveLast()

ShowRe()
MessageBox.Show("تمــــــت عمليـــــة الحـــــــفظ بنجـــــــاح", "حــــــفظ a.sh", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
PhoneFrm_Load(Nothing, Nothing)

Catch ex As Exception
MessageBox.Show("العمليـــــة فشــــــــلت", "خـــــــطأ", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
SaveBtn.Enabled = False
NewBtn.Enabled = True

End Try
ولكن تظهرلى مشكلة عند الاضافة
تظهرلى رسالة العملية فشلت فماهو الحل
فيه طريقة اسهل للحفظ
كود :
dim insertinto as new oledbcommand("insert into tb (name,age) values(@name,@age)",con)
insertinto.parameters.addwithvalue("@name",oledbtype.varchar).value=name.text
insertinto.parameters.addwithvalue("@age",oledbtype.int).value=age.text

كود :
con.open

try


insert into executenonquery

هنا رسالة تم الحفظ



Catch ex As Exception

هنا رسالة الخطا

end try
سعود كتب :فيه طريقة اسهل للحفظ
كود :
dim insertinto as new oledbcommand("insert into tb (name,age) values(@name,@age)",con)
insertinto.parameters.addwithvalue("@name",oledbtype.varchar).value=name.text
insertinto.parameters.addwithvalue("@age",oledbtype.int).value=age.text

كود :
con.open

try


insert into executenonquery

هنا رسالة تم الحفظ



Catch ex As Exception

هنا رسالة الخطا

end try

طب ممكن تعدلى الكود على ما موجود بالكود تبعى
إقتباس :
طب ممكن تعدلى الكود على ما موجود بالكود تبعى
احذفه بشكل كامل وحط هذا بمكانهSmileSmile
او ارفع مثال صغير بنفس الفكرة اعدل عليه.
سعود كتب :فيه طريقة اسهل للحفظ
كود :
dim insertinto as new oledbcommand("insert into tb (name,age) values(@name,@age)",con)
insertinto.parameters.addwithvalue("@name",oledbtype.varchar).value=name.text
insertinto.parameters.addwithvalue("@age",oledbtype.int).value=age.text

كود :
con.open

try


insert into executenonquery

هنا رسالة تم الحفظ



Catch ex As Exception

هنا رسالة الخطا

end try

استخدمت الكود وعدلت فيه لحد ماقدرت لكن بيأتى تعليم خطأ على الجملة الاتيه
insert into executenonquery
خطا معلش شوف انا كتبت تعريفه كذا
كود :
dim insertinto
وطلبت تنفيذه كذا
كود :
insert into executenonquery
اجعله كذا
كود :
insertinto.executenonquery
سعود كتب :خطا معلش شوف انا كتبت تعريفه كذا
كود :
dim insertinto
وطلبت تنفيذه كذا
كود :
insert into executenonquery
اجعله كذا
كود :
insertinto.executenonquery

اخى الحبيب هذا هو الكود الذى استخدمته ولم يظهر به اى اخطاء ولكنه عند التجربة تظهرلى رسالة عدم الحفظ
إقتباس : Dim insertinto As New OleDbCommand("insert into tabel2 (nam,price of buy,price of sell,notes) values(@name,@price of buy,@price of sell,@notes)", Cn)
insertinto.Parameters.AddWithValue("@nam", OleDbType.Integer).Value = TextBox1.Text
insertinto.Parameters.AddWithValue("@price of buy", OleDbType.Integer).Value = TextBox2.Text
insertinto.Parameters.AddWithValue("@price of sell", OleDbType.Integer).Value = TextBox3.Text
insertinto.Parameters.AddWithValue("@notes", OleDbType.Integer).Value = RichTextBox1.Text
Cn.Open()
Try


insertinto.ExecuteNonQuery()

MsgBox("تمت عملية الحفظ بنجاح,حفظ")



Catch ex As Exception

MsgBox("لم يتم الحفظ")

End Try
لا تكتب لم يتم الحفظ وانما اسند دالة الخطا
كود :
Msgbox (Err.Description)
سعود كتب :لا تكتب لم يتم الحفظ وانما اسند دالة الخطا
كود :
Msgbox (Err.Description)

قالى خطأ فى بناء جملة insert into
السلام عليكم

ما جملة الخطأ اخي العزيز؟
الصفحات : 1 2