26-12-14, 10:16 PM
اخي الوليد يوجد خطأ في التعديل و الحذف
الكود التعديل
كود الحذف
الكود التعديل
كود :
Try
Using conn As New OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath() & "\Data.accdb" & ";Persist Security Info=True;Jet OLEDB:Database Password=123")
' التعديل '
Dim sql As String = _
" UPDATE [Student] " & _
" SET [Student_Name]=@Student_Name " & _
" , [Student_CPR]=@Student_CPR " & _
" , [Student_Birth]= @Student_Birth " & _
" , [Student_Join]=@Student_Join " & _
" , [Student_Nation]=@Student_Nation " & _
" , [Student_Sex]=@Student_Sex " & _
" , [Student_D]=@Student_D " & _
" , [Student_Place]=@Student_Place " & _
" , [Student_Address]=@Student_Address " & _
" , [Student_Sick]=@Student_Sick " & _
" , [Student_Vairus]=@Student_Vairus " & _
" , [Student_phone]=@Student_phone " & _
" , [Student_Dad]=@Student_Dad " & _
" , [Student_mom]=@Student_mom " & _
" , [Student_Angel]=@Student_Angel " & _
" , [Student_jobmom]=@Student_jobmom " & _
" , [Student_jobdad]=@Student_jobdad " & _
" , [Student_Famaly]=@Student_Famaly " & _
" , [Student_Pic]=@Student_Pic " & _
" WHERE [id]=@id "
Using cmd As New OleDb.OleDbCommand(sql, conn)
' ترتيب البارامترات هو نفس ترتيب تواجدها في جملة الاسكويل '
cmd.Parameters.AddWithValue("@Student_Name", ComboBox15.Text)
cmd.Parameters.AddWithValue("@Student_CPR", TextBox16.Text)
cmd.Parameters.AddWithValue("@Student_Birth", DateTimePicker6.Value.Date)
cmd.Parameters.AddWithValue("@Student_Join", DateTimePicker5.Value.Date)
cmd.Parameters.AddWithValue("@Student_Nation", ComboBox14.Text)
cmd.Parameters.AddWithValue("@Student_Sex", ComboBox9.Text)
cmd.Parameters.AddWithValue("@Student_D", ComboBox10.Text)
cmd.Parameters.AddWithValue("@Student_Place", ComboBox13.Text)
cmd.Parameters.AddWithValue("@Student_Address", TextBox24.Text)
cmd.Parameters.AddWithValue("@Student_Sick", ComboBox12.Text)
cmd.Parameters.AddWithValue("@Student_Vairus", TextBox19.Text)
cmd.Parameters.AddWithValue("@Student_phone", TextBox23.Text)
cmd.Parameters.AddWithValue("@Student_Dad", TextBox22.Text)
cmd.Parameters.AddWithValue("@Student_mom", TextBox21.Text)
cmd.Parameters.AddWithValue("@Student_Angel", TextBox20.Text)
cmd.Parameters.AddWithValue("@Student_jobmom", TextBox18.Text)
cmd.Parameters.AddWithValue("@Student_jobdad", TextBox17.Text)
cmd.Parameters.AddWithValue("@Student_Famaly", ComboBox11.Text)
Using ms As New IO.MemoryStream
Me.PictureBox2.Image.Save(ms, Imaging.ImageFormat.Png)
cmd.Parameters.AddWithValue("@Student_Pic", ms.ToArray())
End Using
conn.Open()
Dim result As Integer = cmd.ExecuteNonQuery()
conn.Close()
If result > 0 Then
MessageBox.Show("تم التعديل بنجاح", "مبروك", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("لم أجد الرقم", "تحديث", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Tryكود الحذف
كود :
Try
Using conn As New OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath() & "\Data.accdb" & ";Persist Security Info=True;Jet OLEDB:Database Password=123")
' الحذف '
Dim sql As String = _
" DELETE FROM [Student] " & _
" SET [Student_Name]=@Student_Name " & _
" , [Student_CPR]=@Student_CPR " & _
" , [Student_Birth]= @Student_Birth " & _
" , [Student_Join]=@Student_Join " & _
" , [Student_Nation]=@Student_Nation " & _
" , [Student_Sex]=@Student_Sex " & _
" , [Student_D]=@Student_D " & _
" , [Student_Place]=@Student_Place " & _
" , [Student_Address]=@Student_Address " & _
" , [Student_Sick]=@Student_Sick " & _
" , [Student_Vairus]=@Student_Vairus " & _
" , [Student_phone]=@Student_phone " & _
" , [Student_Dad]=@Student_Dad " & _
" , [Student_mom]=@Student_mom " & _
" , [Student_Angel]=@Student_Angel " & _
" , [Student_jobmom]=@Student_jobmom " & _
" , [Student_jobdad]=@Student_jobdad " & _
" , [Student_Famaly]=@Student_Famaly " & _
" , [Student_Pic]=@Student_Pic " & _
" WHERE [id]=@id "
Using cmd As New OleDb.OleDbCommand(sql, conn)
cmd.Parameters.AddWithValue("@Student_Name", ComboBox15.Text)
cmd.Parameters.AddWithValue("@Student_CPR", TextBox16.Text)
cmd.Parameters.AddWithValue("@Student_Birth", DateTimePicker6.Value.Date)
cmd.Parameters.AddWithValue("@Student_Join", DateTimePicker5.Value.Date)
cmd.Parameters.AddWithValue("@Student_Nation", ComboBox14.Text)
cmd.Parameters.AddWithValue("@Student_Sex", ComboBox9.Text)
cmd.Parameters.AddWithValue("@Student_D", ComboBox10.Text)
cmd.Parameters.AddWithValue("@Student_Place", ComboBox13.Text)
cmd.Parameters.AddWithValue("@Student_Address", TextBox24.Text)
cmd.Parameters.AddWithValue("@Student_Sick", ComboBox12.Text)
cmd.Parameters.AddWithValue("@Student_Vairus", TextBox19.Text)
cmd.Parameters.AddWithValue("@Student_phone", TextBox23.Text)
cmd.Parameters.AddWithValue("@Student_Dad", TextBox22.Text)
cmd.Parameters.AddWithValue("@Student_mom", TextBox21.Text)
cmd.Parameters.AddWithValue("@Student_Angel", TextBox20.Text)
cmd.Parameters.AddWithValue("@Student_jobmom", TextBox18.Text)
cmd.Parameters.AddWithValue("@Student_jobdad", TextBox17.Text)
cmd.Parameters.AddWithValue("@Student_Famaly", ComboBox11.Text)
Using ms As New IO.MemoryStream
Me.PictureBox2.Image.Save(ms, Imaging.ImageFormat.Png)
cmd.Parameters.AddWithValue("@Student_Pic", ms.ToArray())
End Using
conn.Open()
Dim result As Integer = cmd.ExecuteNonQuery()
conn.Close()
If result > 0 Then
MessageBox.Show("تمت الحذف بنجاح", "مبروك", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("لم أجد الرقم", "حذف", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
