Inserting a dataset to another

ballwah

Member
Joined
Aug 7, 2006
Messages
15
Programming Experience
Beginner
Hi there,

I've imported a set of data from Excel sheet to a dataset in VB.net and would like to update them to the database.
Instead of inserting rows by rows, how can I add the new dataset to the the dataset of the database?

It would be great if someone can help me solve this problem. Many thanks!!:p
 
DataTable.Merge seems to indicate that it isnt necessary to use two of the same type of datatable, only that the tables have similar schema..

Try arranging your datatables so they have similar schemas and then call databaseDT.Merge(excelSheetDT)
 
tableadapters are typed; you'd have to use a generic dataadapter I think..

ok, this is another one of those terms that my mind is kinda vague on... cjard could you please explain to me what a 'typed' tableadapter is, and how it differs from an 'untyped' (?). sorry, there are somethings i just have no clue on :eek:

cheers mate
regards
adam
 
DataTable.Merge seems to indicate that it isnt necessary to use two of the same type of datatable, only that the tables have similar schema..

Try arranging your datatables so they have similar schemas and then call databaseDT.Merge(excelSheetDT)


Hi cjard,
Thanks for your reply.
Can I just easily use the merge function and 2 datasets can then be combined by adding the excel dataset to the database one?
 
Has your dataset that you have created to pull in the information from Excel got the same schema as your database?

If so, then as cjard says, you can make a merge between your two datasets.

Anti-Rich, to answer your question I kind of stole this :)
typed Data set is assoicated with XML Schema.
Untyped data set not assoicated with XML Schema.


A DataSet can be typed or untyped. A typed DataSet is a dataset, which is created based a given XML Schema definition file (XSD file). Information from the schema (tables, columns, etc.) is generated and compiled into the new DataSet class as a set of first-class objects and properties.

Because a typed DataSet class inherits from the base DataSet class, the typed class assumes all of the functionality of the DataSet class and can be used with methods that take an instance of a DataSet class as a parameter

An untyped DataSet, in contrast, has no corresponding built-in schema. As in a typed dataset, an untyped DataSet contains tables, columns - but those are exposed only as collections.

You can use either type of DataSet in your application. However, Visual Studio has more tool support for typed DataSets, and they make programming with the DataSet much easier and less error-prone.

..So basically (I think!) a typed dataset example would be me.dataset1.datatable1 and an untyped example would be me.dataset1.tables("datatable1")

Regards,
 
..So basically (I think!) a typed dataset example would be me.dataset1.datatable1 and an untyped example would be me.dataset1.tables("datatable1")

Regards,
Yes, but:

Typed datasets can be accessed in untyped fashion too
Typed datasets are classes created by the IDE, but you can infer that they are only typed because there is purpose built code behind them:

VB.NET:
Public Property dataTable1
  Get
    return DirectCast(me.tables("datatable1"), dataTable1)
  End Get
End Property

I believe that merge can work with anything where the schemas are sufficiently similar, but I dont know if this applies to names, or source columns, or what..

if two datatables A and B, having columns named differntly (X and Y) but both referencing the SourceColumn (in the database) of Z.. I dont know if these tables can be merged or not.

Best bet is just to try!

Merge works in upsert fashion: existing records are updated, nonexisting ones are added
 
ok, this is another one of those terms that my mind is kinda vague on... cjard could you please explain to me what a 'typed' tableadapter is, and how it differs from an 'untyped' (?). sorry, there are somethings i just have no clue on :eek:

There is no untyped tableadapter. A TableAdapter is purely a creation of the IDE, a bunch of code written for you by a wizard, which essentially aggregates a DataAdapter (used to move data between db and client), several commands that pertain to just one table, and hence it knows how to read and write just one DataTable.
 
Back
Top