|
code show as below,
Private Sub btnRefresh_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
dim newDset as new dataset 'Create a new dataset
Dim str As String = "DRIVER = {MySQL ODBC 3.51 driver}; SERVER = localhost; DATABASE = jsd; UID = root; PASSWORD = ji; OPTION = 3"
Dim conn As New OdbcConnection (str)
Dim newtblmaster As New DataTable 'Newly created dataTable to store the master table
Dim newtblDetail As New DataTable 'Newly created from table dataTable
Me.dset.Clear () 'First clear the original dataset
conn.Open ()
Dim strSql1 As String = "select * from tableMaster"
Dim strSql2 As String = "select * from tableMaster
dataAdapterTablemaster.SelectCommand = New OdbcCommand (strSql1, conn)
dataAdapterTableDetail.SelectCommand = New OdbcCommand (strSql2, conn)
dataAdapterTablemaster.Fill (newtblmaster)
dataAdapterTableDetail.Fill (newtblDetail)
conn.Close ()
newDset.Tables.Add (newtblmaster)
newDset.Tables.Add (newtblDetail)
Dim relorderTodetail2 As DataRelation '
relorderTodetail2 = New DataRelation ("tablemasterTabledetail", newtblmaster.Columns ("ID"), newtblDetail.Columns ("ID"))
newDset.Relations.Add (relorderTodetail2) This shows the error 'The association named' tablemasterTabledetail 'already belongs to this DataSet.
DataGrid1.DataSource = newtblmaster 'The two tables are displayed in association
DataGrid2.DataSource = newtblmaster
DataGrid2.DataMember = "tablemasterTabledetail"
End Sub |
|