How can I save the data in dataset into database

  • Hi,

    I have a dataset, which has stored some table, I want to create a same table on the same database, and same the data in the dataset to the new table, the following code can run, but I don't know why I can't find the table DT1 in my database, is there any step I missed? could you please help me check it? Thanks a lot.

    Thanks

    Lindsay

    DataTable dt1 = new DataTable("DT1");

    DataTable table = result.DataSet.Tables;

    int columnCount = table.Columns.Count;

    for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)

    {

    dt1.Columns.Add(table.Columns[columnIndex].ColumnName, table.Columns[columnIndex].DataType);

    }

    result.DataSet.Tables.Add(dt1);

  • a datatable is a local object that exists in memory until you call UpdateDataTable from your DataAdapter, which would synchronize any changes....

    typically you would use a typed dataset that has the exact structure of the table on the server, LoadDataTable, make changes, then UpdateDataTable to get the changes out to the server.

    does that sound like what you are missing?

    dt1 would not exist anywhere...the table you would look for would be the value found in result.DataSet.Tables.TableName or dt1.TableName

    somewhere i'm expecting myDataAdapter.UpdateDataTable(result.DataSet.Tables😉

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Yes, you are right. Thanks a lot:)

    Thanks

    Lindsay

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply