Your code has problems. You use dataadapters on one and TableAdapters on the other. You talk about using databinding to push the changes and now your talking about using properties. Both will work if you use them correctly.
Here is a bare bones examples of using databinding,
Add a datagridview and button to PassBoundData
Add two textboxes to ReceiveDataRowCode:Imports System.Data.SqlClient Public Class PassBoundData 'I always store my connectionstrings in the project Setting Private con As New SqlConnection(My.Settings.BooksDBConnectionString) Private da As New SqlDataAdapter("Select BookId, BookName, Author From Books ORDER BY BookName", con) Private dt As New DataTable 'I prefer using a BindingSource with the DataGridView because it has many built in function for working/manipulating the data Private bs As New BindingSource 'If your only working with one table then you can use a CommandBuilder to create the SQL Add/Update/Delete commands if your table has a PrimaryKey Private cmdBuilder As New SqlCommandBuilder(da) Private Sub DataAdapterDemo_Load(sender As Object, e As EventArgs) Handles Me.Load Try con.Open() da.Fill(dt) bs.DataSource = dt Me.DataGridView1.DataSource = bs Catch ex As Exception MessageBox.Show(ex.ToString) End Try End Sub Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click Try bs.EndEdit() da.Update(dt) Catch ex As Exception MessageBox.Show(ex.ToString) End Try End Sub Private Sub DataGridView1_RowHeaderMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.RowHeaderMouseClick Dim row As DataRowView = DirectCast(bs.Current, DataRowView) Dim frm As New ReceiveDataRow(row) frm.ShowDialog() bs.EndEdit() End Sub End Class
The changes you make in ReceiveDataRow will be pushed back to PassBoundData and will show in the dgv.Code:Imports System.ComponentModel Public Class ReceiveDataRow Private rowEdit As DataRowView Public Sub New(row As DataRowView) ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. rowEdit = row End Sub Private Sub ReveiveDataRow_Load(sender As Object, e As EventArgs) Handles Me.Load Me.TextBox1.Text = rowEdit("BookName").ToString Me.TextBox2.Text = rowEdit("Author").ToString End Sub Private Sub ReceiveDataRow_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing rowEdit("BookName") = Me.TextBox1.Text rowEdit("Author") = Me.TextBox2.Text End Sub End Class




Reply With Quote
