الاخوة الافاضل
عندى داتا جريد ياخد البيانات من جدولين
رقم العميل اسم العميل كمبوبوكس ( جملة - تجزئة )
عند حفظ تغيير نوع العميل من جملة او تجزئة يعطى رسالة خطأ
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("provider=microsoft.ace.oledb.12.0;data source=customers.accdb")
Dim da As New OleDbDataAdapter
Dim dt As New DataTable
Dim dttype As New DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim datype As New OleDbDataAdapter("select * from cust_type", con)
datype.Fill(dttype)
Column3.DataSource = dttype
Column3.DisplayMember = "custype_name"
Column3.ValueMember = "custype_id"
'**********************************************
da = New OleDbDataAdapter("SELECT customers.cust_id, customers.cust_name, cust_type.custype_name FROM cust_type INNER JOIN customers ON cust_type.[custype_id] = customers.[custype_id] order by customers.cust_id;", con)
dt = New DataTable
da.Fill(dt)
For i = 0 To dt.Rows.Count - 1
DataGridView1.Rows.Add()
DataGridView1.Rows(i).Cells(0).Value = dt(i)(0)
DataGridView1.Rows(i).Cells(1).Value = dt(i)(1)
DataGridView1.Rows(i).Cells(2).Value = dt(i)(2)
Next
End Sub
Private Sub DataGridView1_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError
On Error Resume Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'كود الحفظ
Dim cmd As New OleDbCommand(String.Empty, con)
con.Open()
For Each r As DataGridViewRow In DataGridView1.Rows
If r.IsNewRow Then Exit For
If IsNumeric(r.Cells(2).Value) Then
cmd.CommandText = "update customers set cust_name=@cust_name,custype_id=@custype_id where cust_id=@cust_id"
With cmd.Parameters
.Clear()
.AddWithValue("@cust_name", r.Cells(1).Value)
.AddWithValue("@custype_id", r.Cells(2).Value)
.AddWithValue("@cust_id", r.Cells(0).Value)