لدي قاعدة بيانات مكونة من جدول واحد وعملت برنامج يربط مع القاعدة ويعرضه في الداتا كرد واظفت ازرار تعديل وحذف لكل سجل لكن ماعملت معي ارجو تعديل الكود الاسفل او عمل برنامج مبسط لكل اساتذتي الاجلاء لاني بحث في جميع المنتديات لكن لم اجد الحل
Imports System.Data.SqlClient
Imports System.Data
Public Class Form1
Dim queryString As String
Dim adapter As New SqlDataAdapter
Dim StrTbl As String
Dim dataSet As DataSet
Dim Dt As New DataTable
Private viewAc As New DataView
Dim Myds As New DataSet
Public connectionString As String = "Data Source=" + My.Computer.Name & "\SQLEXPRESS" + ";Initial Catalog=office;Integrated Security=True"
Public conn As New SqlConnection(connectionString)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim connectionString As String = "Data Source=FLH;Initial Catalog=office;Integrated Security=True"
Dim conn As New SqlConnection(connectionString)
conn.Open()
If conn.State = ConnectionState.Open Then
MsgBox("تم الأتصال بقاعدة البيانات بنجاح", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRight = False + MsgBoxStyle.MsgBoxRtlReading = False + MsgBoxStyle.OkOnly, "برنامج الاتصال بقاعدة البيانات")
Else
MsgBox("لم يتم الاتصال ", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRight = False + MsgBoxStyle.MsgBoxRtlReading = False + MsgBoxStyle.OkOnly, "برنامج الاتصال بقاعدة البيانات")
End If
Dim Myds As New DataSet
Dim sql(1) As String
sql(0) = "select * from department "
Dim adapter As New SqlDataAdapter(sql(0), conn)
adapter.Fill(Myds, "department")
adapter.Fill(Dt)
conn.Close()
viewAc = Dt.DefaultView
DGRD.Rows.Clear()
For I As Integer = 0 To viewAc.Count - 1
With viewAc.Item(I)
Dim depid As String = .Item("depid")
Dim namedep As String = .Item("namedep")
Dim row As String() = {depid, namedep, "حفظ", "حذف"}
DGRD.Rows.Add(row)
End With
Next
End Sub
Private Sub DGRD_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGRD.CellContentClick
Try
'UPDATE
If e.ColumnIndex = 2 Then
With DGRD.CurrentRow
Dim depid As Integer = .Cells(0).Value
Dim namedep As String = .Cells(1).Value
Dim conn As New SqlConnection(connectionString)
Using command As New SqlCommand("department", conn)
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add(New SqlParameter("@depid", depid))
command.Parameters.Add(New SqlParameter("@namedep", namedep))
conn.Open()
command.ExecuteNonQuery()
End Using
End With
MsgBox("تم تعديل السجل")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class