03-02-20, 02:30 AM
(03-02-20, 02:10 AM)tahaayyoub كتب : مساعدة من فضلكم
عند ضغط زر اضافة او تعديل فان الحذث يقوم باضافة البيانات المطلوبة الا الحقل الاخير دائما ما يبقى خاليا مع ان الكود صحيح، والحقل attab من nvarchar وحولته الى real لكن دون جدوى اين الخلل
هذا كود التعديل وتقريبا نفسه كود الاضافة
Private Sub ToolStripButton4_Click(sender As Object, e As EventArgs) Handles ToolStripButton4.Click
Dim i As Integer = DataGridView1.CurrentRow.Index
cmd = New SqlCommand("update liste_pv set nom_pv=@id2,attab=@id3 where id_proces_v=@id1", con)
cmd.Parameters.Clear()
With cmd.Parameters
.AddWithValue("@id1", DataGridView1.Rows(i).Cells(0).Value.ToString)
.AddWithValue("@id2", DataGridView1.Rows(i).Cells(1).Value.ToString)
.AddWithValue("@id3", DataGridView1.Rows(i).Cells(2).Value.ToString)
End With
con.Open()
cmd.ExecuteNonQuery()
MsgBox(DataGridView1.Rows(i).Cells(2).Value.ToString)
con.Close()
Form1_load(Nothing, Nothing)
End Sub
![]()
التحديث يتم على السطر المحدد،
وتاكد من الحقل attab انه رقم فعلا
وان العمود الذي يظهر باسم (الاتعاب) هو فعلا الحل attab
واستخدمم النوع int غن كان عدد صحيح او float ان العدد يشمل كسور
كود :
Private Sub ToolStripButton4_Click(sender As Object, e As EventArgs) Handles ToolStripButton4.Click
Dim r As DataGridViewRow = DataGridView1.CurrentRow
Dim cmd As New SqlCommand("UPDATE [liste_pv] SET [nom_pv]=@nom_pv,[attab]=@attab WHERE [id_proces_v]=@id_proces_v", con)
With cmd.Parameters
.AddWithValue("@nom_pv", r.Cells(1).Value.ToString)
.AddWithValue("@attab", Val(r.Cells(2).Value.ToString))
.AddWithValue("@id_proces_v", r.Cells(0).Value.ToString)
End With
con.Open()
If cmd.ExecuteNonQuery() > 0 Then
MsgBox("تم التحديث", MsgBoxStyle.Information)
Else
MsgBox("فشل التحديث", MsgBoxStyle.Critical)
End If
MsgBox(r.Cells(2).Value.ToString)
con.Close()
Form1_load(Nothing, Nothing)
End Sub
