locked
Complete Data Transfer one access.mdb to another access.mdb RRS feed

  • Question

  • User1015862149 posted

    I need to transfer the older access.mdb file to newly create access.mdb some addtion fields are add in newly create mdb file by using C#.net its very aurgent.

    Tuesday, August 6, 2013 12:41 AM

Answers

  • User-1199946673 posted

    I have tried the above code

    But you changed the syntax. When the Database is protected with a password, you need to add the PWD argument:

    string selQuery = "INSERT INTO [Drawer](Draw_Code,Draw_Name,Cab_Code,Remarks,Delflag,Reference1,Reference2,Reference3,Reference4) SELECT Draw_Code,Draw_Name,Cab_Code,Remarks,Delflag,Reference1,Reference2,Reference3,Reference4 FROM [MS Access;DATABASE=G:\CabinetPorting\CabinetPorting\old Database\CabinetDB.mdb;PWD=pslCAB].[Drawer]";
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 9, 2013 11:17 AM
  • User1015862149 posted

    Thank Dude.. Its working fine.....

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 10, 2013 3:30 AM

All replies

  • User-306750178 posted

    Hi,

    You would just need to make a Jet or ADO connection to the other database, and then create a recordset that either updates or inserts your data.

    How are you packaging the data that is going to be sent to the other database? Where is the other database? Is it on your LAN? If so, how many database instances will be sending data to the other database (just you, or 100 other users?) Also, will the receiving database be used for transactions in real time other than the ones you are sending? Will you use a DSN?

    If you were using a form, for example, and sending a user's first and last names, identifying the record with a PK that was the same in both databases, your code would look something like:

    Dim lPK As Long
    Dim sLast As String
    Dim sFirst As String
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim sSQL As String

    lPK = Me.ID
    sLast = Me.LastName
    sFirst = Me.FirstName

    sSQL = "UPDATE tblMyOtherDatabaseTable " & _
    "SET [LastName] = '" & sLast & "', " & _
    "[FirstName] = '" & sFirst & "' " & _
    "WHERE ID = " & lPK

    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=\my_path\MyOtherDatabase.mdb;" & _
    "User ID=userid;" & _
    "Password=password;"

    Set rs = New ADODB.Recordset
    rs.Open sSQL, cn, adOpenDynamic, adLockOptimistic

    'the act of opening the recordset using the connection object updates the database.

    So something like this would work. You can also use a DSN and lose some of the connection string.

    Refer below links

    http://p2p.wrox.com/access/69820-transfer-data-one-database-mdb-another.html

    http://www.techrepublic.com/forums/questions/transfer-access-view-query-to-another-mdb/

    I hope these will help you.

    Tuesday, August 6, 2013 12:48 AM
  • User1015862149 posted

    I need to to transfer the entire data from one table to another Empty table using the ADO connection

    using c#.net

    Tuesday, August 6, 2013 1:44 AM
  • User-1199946673 posted

    your code would look something like:

    You're showing classic ASP (Vb script)!

    Tuesday, August 6, 2013 4:55 AM
  • User-1199946673 posted

    When you've Access, then you could easliy do this by linking the table in the second database into the first database., and then you can use both tables just like they are inside the same database.

    In code, you can link them also, but you don't need to. When the structure of both tables is exactly the same, create a connection with the "New" database, and then execute this:

     

    INSERT INTO [YourNewTable] SELECT * FROM [MS Access;DATABASE=D:\Path\To\OldDatabase.mdb].[YourOldTable]

    If the structure is not the same:

    INSERT INTO [YourNewTable] (field1, field2, field3) SELECT field1, field2, field3 FROM [MS Access;DATABASE=D:\Path\To\OldDatabase.mdb].[YourOldTable]
    


    Tuesday, August 6, 2013 5:13 AM
  • User1015862149 posted

    I have tried the above code but am having error during run the program as (Invalid argument. and error code -2147467259 )

    and i showed my code below

           string conString = @"Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=G:\CabinetPorting\CabinetPorting\New                  Database\CabinetDB.mdb;Jet OLEDB:Database Password=pslCAB";
                OleDbConnection dbconn = new OleDbConnection(conString);
                OleDbDataAdapter dAdapter = new OleDbDataAdapter();
                OleDbCommand dbcommand = new OleDbCommand();

                try
                {
                    if (dbconn.State == ConnectionState.Closed)
                        dbconn.Open();
                    //string selQuery = "INSERT INTO [Drawer] SELECT * FROM [MS Access;DATABASE=" +
                    //        "\\CabinetDB.mdb" + "; Jet OLEDB:Database Password=pslCAB;].[Drawer]";

                    string selQuery = "INSERT INTO [Drawer](Draw_Code,Draw_Name,Cab_Code,Remarks,Delflag,Reference1,Reference2,Reference3,Reference4) SELECT Draw_Code,Draw_Name,Cab_Code,Remarks,Delflag,Reference1,Reference2,Reference3,Reference4 FROM [MS Access;DATABASE=Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=G:\\CabinetPorting\\CabinetPorting\\old Database\\CabinetDB.mdb;Jet OLEDB:Database Password=pslCAB;].[Drawer]";
                    dbcommand.CommandText = selQuery;
                    dbcommand.CommandType = CommandType.Text;
                    dbcommand.Connection = dbconn;
                    int result = dbcommand.ExecuteNonQuery();
                }
                catch (InvalidCastException r)
                {
                    throw (r);  
                }

    plz replay me..its urgent

    Friday, August 9, 2013 8:26 AM
  • User-1199946673 posted

    I have tried the above code

    But you changed the syntax. When the Database is protected with a password, you need to add the PWD argument:

    string selQuery = "INSERT INTO [Drawer](Draw_Code,Draw_Name,Cab_Code,Remarks,Delflag,Reference1,Reference2,Reference3,Reference4) SELECT Draw_Code,Draw_Name,Cab_Code,Remarks,Delflag,Reference1,Reference2,Reference3,Reference4 FROM [MS Access;DATABASE=G:\CabinetPorting\CabinetPorting\old Database\CabinetDB.mdb;PWD=pslCAB].[Drawer]";
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 9, 2013 11:17 AM
  • User1015862149 posted

    Thank Dude.. Its working fine.....

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 10, 2013 3:30 AM