none
Partial typed dataadapter without database? RRS feed

  • Question

  • Hi!
    I would like to write a dataadapter that moves data between an open Excel Workbook and a typed data set (this is an Excel AddIn). The excel workbook is structured for user ergonomy, the data set is structured for correctness and programmer access and the adapter should map between the two wildly different representations.
    However, I see no way to do that.
    • Defining a class that inherits from IDataAdapter gives me fill and update methods that accept the untyped DataSet with no compile time checking whether I pass the correct data set.
    • Using the Wizard in the DataSet Designer always demands a database connection and sql, which I don't have here.
    In an ideal World, there would be a generic interface like "IDataAdapter<DataSetType>" where the fill and update method signatures have the correct types.
    Is there a way to achieve a similar effect?

    Lots of Greetings!
    Volker

    Wednesday, January 14, 2009 9:48 PM

All replies

  • Excel is not really a database and each column in spreadsheet(s) may contain mixed types of data. That is the reason why you cannot have predefined structure and generate typed classes based on it.
    Val Mazur (MVP) http://www.xporttools.net
    Friday, January 16, 2009 11:09 AM
    Moderator
  • Hi!
    There might be a misunderstanding: I do not want to create a data set or data adapter from an excel sheet, I would like to create a data adapter from a data set. It's the adapters job to bother about the sheet and its problems. (And my job to code this into the appropriately typed fill and update methods.)

    Given the way the visual studio wizards are made, it's probably a bit unusual, so please let me elaborate:

    • Visual Studio's way: Given a database, create the dataset and the adapter with tool support. Problem, if the database is not supported or does not lend itself to some foolproof mechanism for generating the set and adapter.
    • What I want: Given a typed DataSet, create an adapter skeleton that provides (typed) empty fill and update methods and allows me to implement the "database" communication.
    Maybe it helps understanding if you don't think about excel, but generalize the problem to:
    • given a proprietary data file format,
    • define manually (using the designer) a data set representing its contents in a programmer friendly way (third normal form, keys, references, constraints and so on) and
    • get Visual Studio to create a typed adapter (with empty fill/update methods) which I will add code to for reading and writing the file.
    For this, I think a typed dataadapter interface would be very helpful since it allows compile checking that the right dataset goes to the right adapter. Does such a thing exist?

    Lots of Greetings!
    Volker

    Friday, January 16, 2009 12:23 PM