تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
خطأ في كود الجمع عند الحفظ
#1
هذين كودين يشتغلان 100٪ عند حذف الجزئية الخاصة
بتجميع الدرجات.

الكود الأول  للفورم 1: لحفظ درجات المصفوفة (on)
مع جمعها مع المصفوفة (to) التي قيمتها (0)
ثم اظهار الناتج في مصفوفة (tr)

الكود الثاني للفورم 2: لحفظ درجات المصفوفة (to) مع تحديث الجمع المصفوفة (tr)
كود :
*أولا: فورم رصد درجات الأعمال*
`
Private Sub Save_Grade()
   Try
       If DataGridView1.Rows.Count = 0 OrElse (DataGridView1.Rows.Count = 1 AndAlso DataGridView1.Rows(0).IsNewRow) Then
           MessageBox.Show(" عفواً ، لا توجـد بيانــات للحفظ", "تنبيــه", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
           Exit Sub
       End If

       Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; " & "Data Source=" & Application.StartupPath & "\DataBase\Data_Base.accdb")
       If DataGridView1.Rows.Count = 0 Then Exit Sub
       con.Open()

       For i As Integer = 0 To DataGridView1.Rows.Count - 2
           Dim IDStudent As Integer = Val(DataGridView1.Rows(i).Cells(0).Value)
           Dim IDClas As Integer = CInt(listClas.SelectedIndices(0) + 1)
           Dim ClassroomID As Integer = CInt(Combroom.SelectedIndex + 1)
           Dim IDSemester As Integer = Val(CombSemester.Text)
           Dim ONValue As Integer = Val(DataGridView1.Rows(i).Cells(5).Value)
           DataGridView1.Rows(i).Cells(7).Value = ONValue

           Dim query As String = "SELECT * FROM TBL_Final1 WHERE IDStudent = ? AND IDClas = ? AND ClassroomID = ? AND IDSemester = ?"
           Dim command As New OleDbCommand(query, con)
           command.Parameters.AddWithValue("?", IDStudent)
           command.Parameters.AddWithValue("?", IDClas)
           command.Parameters.AddWithValue("?", ClassroomID)
           command.Parameters.AddWithValue("?", IDSemester)
           Dim reader As OleDbDataReader = command.ExecuteReader()

           If reader.HasRows Then
               reader.Close()
               query = "UPDATE TBL_Final1 SET ON" & CombCourses.SelectedIndex + 1 & " = ? WHERE IDStudent = ? AND IDClas = ? AND ClassroomID = ? AND IDSemester = ?"
               command = New OleDbCommand(query, con)
               command.Parameters.AddWithValue("?", ONValue)
               command.Parameters.AddWithValue("?", IDStudent)
               command.Parameters.AddWithValue("?", IDClas)
               command.Parameters.AddWithValue("?", ClassroomID)
               command.Parameters.AddWithValue("?", IDSemester)
               command.ExecuteNonQuery()
           Else
               reader.Close()
               query = "INSERT INTO TBL_Final1 (IDStudent, IDClas, ClassroomID, IDSemester, ON" & CombCourses.SelectedIndex + 1 & ") VALUES (?, ?, ?, ?, ?)"
               command = New OleDbCommand(query, con)
               command.Parameters.AddWithValue("?", IDStudent)
               command.Parameters.AddWithValue("?", IDClas)
               command.Parameters.AddWithValue("?", ClassroomID)
               command.Parameters.AddWithValue("?", IDSemester)
               command.Parameters.AddWithValue("?", ONValue)
               command.ExecuteNonQuery()
           End If
       Next
       con.Close()
       MsgBox("تم رصد درجــات الصــف : " & " " & listClas.Text & Chr(13) & " لمــادة : " & CombCourses.Text & " * بنجــاح " & "", MsgBoxStyle.Information, "الإجـــراء")
   Catch ex As Exception
       MsgBox(Err.Description, MsgBoxStyle.Information)
   Finally
   End Try
End Sub

-----------------------------------------```

*ثانيا: فورم رصد درجات الامتحان*

Private Sub Save_Grade()
   Try
       If DataGridView1.Rows.Count = 0 OrElse (DataGridView1.Rows.Count = 1 AndAlso DataGridView1.Rows(0).IsNewRow) Then
           MessageBox.Show(" عفواً ، لا توجـد بيانــات للحفظ", "تنبيــه", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
           Exit Sub
       End If

       Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; " & "Data Source=" & Application.StartupPath & "\DataBase\Data_Base.accdb")
       If DataGridView1.Rows.Count = 0 Then Exit Sub
       con.Open()

       For i As Integer = 0 To DataGridView1.Rows.Count - 2
           Dim IDStudent As Integer = Val(DataGridView1.Rows(i).Cells(0).Value)
           Dim IDClas As Integer = CInt(listClas.SelectedIndices(0) + 1)
```
إذا طُعِنتَ من الخلفِ فاعلمْ أنك في المقدمةِ
الرد }}}
تم الشكر بواسطة:


الردود في هذا الموضوع
خطأ في كود الجمع عند الحفظ - بواسطة مصمم هاوي - 19-04-25, 10:40 PM


التنقل السريع :


يقوم بقرائة الموضوع: