| |

VerySource

 Forgot password?
 Register
Search
View: 1639|Reply: 13

Why does the program only refresh once?

[Copy link]

2

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-10 12:00:01
| Show all posts |Read mode
A winForm program with two datagrids displayed in the main interface
The datagrid above shows the master table, and the datagrid association below shows the slave table,


I entered a master-slave table in another interface and then
Added a refresh button in the main interface and newly created one
dataset, refresh it, you can
The main interface displays the data just entered in another interface in the main interface.
But when adding data in another interface, return to the main interface, and then click the "Refresh" button
It shows: the association named 'masterAndDetail' already belongs to this DataSet error message
How can we clear the original association?
Reply

Use magic Report

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-11 15:36:02
| Show all posts
Post the error code ~
Reply

Use magic Report

2

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-1-13 18:36:01
| Show all posts
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
Reply

Use magic Report

2

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-1-14 09:27:02
| Show all posts
sorry, Dim strSql2 As String = "select * from tableMaster
Should be changed to Dim strSql2 As String = "select * from tableDetail"
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-15 14:54:01
| Show all posts
Traditional is ugly
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-17 20:00:02
| Show all posts
Top. Follow.
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-17 21:09:01
| Show all posts
Dim strSql1 As String = "select * from tableMaster"
        Dim strSql2 As String = "select * from tableMaster
There is a problem
Reply

Use magic Report

1

Threads

23

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-1-19 20:27:01
| Show all posts
Clear the binding and re-bind
Reply

Use magic Report

2

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-1-22 00:45:01
| Show all posts
toniannianyss:
dim strsql2 as string = "select * fro tableMaster" is a typo when I upload a file
Reply

Use magic Report

2

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-1-22 02:54:01
| Show all posts
to:irwin8888:
I have cleared the binding
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list