Results 1 to 2 of 2

Thread: dataset problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    5

    dataset problem

    hi all

    I fill my dataset from two different databases using odbc and sql adapter. But i need to update my parodox table data with data from sql table.

    which way o method i need to use . i have no idea

    my code to load data works and returns result
    vb.net Code:
    1. ' load data to dataset
    2.  Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    3.         Dim s As String
    4.         s = "DRIVER=Microsoft Access Paradox Driver (*.db);UID=admin;" & _
    5.             "UserCommitSync=Yes;Threads=3;SafeTransactions=0;ParadoxUserName=admin;ParadoxNetStyle=4.x;Paradox;" & _
    6.             "NetPath={0};" & _
    7.             "PageTimeout=600;MaxScanRows=8;MaxBufferSize=2048;" & _
    8.             "FIL=Paradox 5.X;DriverId=538;" & _
    9.             "DefaultDir={0};" & _
    10.             "DBQ={0};" & _
    11.             "CollatingSequence=ASCII"
    12.              s = "FILEDSN=paradox.dsn"
    13.         Dim c As String
    14.         c = "server=serveris;user id=sa;password=mypsw;Database=database"
    15.         Dim sSQL As String
    16.         Dim d As New DataSet()
    17.         Dim f As New DataSet()
    18.         ' Load the target data and name the table
    19.         Dim oConn = GetNewConnection()
    20.         sSQL = "SELECT f1,f2  FROM  test1;"
    21.  
    22.         Dim adapter As Odbc.OdbcDataAdapter
    23.         adapter = New Odbc.OdbcDataAdapter(sSQL, s)
    24.         adapter.TableMappings.Add("table", "test1")
    25.         d = New DataSet()
    26.         adapter.Fill(d, "test1")
    27.         d.AcceptChanges()
    28.         ' Load the source data, set table name and PK
    29.         Dim cSQL As String
    30.         ' Create and open a new connection to local backup MDB
    31.         Dim Conn = GetNewConnectionSQL()
    32.         cSQL = "SELECT f1,f2  FROM test2;"
    33.         Dim cadapter As SqlClient.SqlDataAdapter
    34.         cadapter = New SqlClient.SqlDataAdapter(cSQL, c)
    35.         cadapter.TableMappings.Add("table", "test2")
    36.         f = New DataSet()
    37.         cadapter.Fill(f, "test2")
    38.        d.Merge(f)
    39.         datagrid.DataSource = d
    40.  
    41.            End Sub
    What can i do to save data from test 2 to test1 table ?? please give direction
    Thanks .
    Last edited by Hack; Oct 19th, 2007 at 08:53 AM. Reason: Added Highlight Tags

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: dataset problem

    Please use the appropriate code tags when posting code to improve readability.

    As far as a DataAdapter is concerned a DataTable is a DataTable is a DataTable. The DataAdapter doesn't care in the slightest where the data in the DataTable came from. This code:
    vb.net Code:
    1. adapter1.AcceptChangesDuringFill = False
    2.  
    3. Dim table As New DataTable
    4.  
    5. adapter1.Fill(table)
    6. adapter2.Update(table)
    will work fine as long as the second DataAdapter has the appropriate InsertCommand. Note that that first line is crucial to ensure that all the DataRows appear to be Added so the second DataAdapter knows to insert them.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width