0

This may seem an odd question.

I have never used classes other than within simple tutorials etc.

What I am trying to do is to take text data that is in a datatable and assign certain cells or groups of cells to be a data class.

For example, say I had plumbing data I would have an overall class of part type that had things like part number, location, unit cost, manufacturer's name etc. as a top level class called, say, 'PART' and then a sub-class for specific parameters such as radius which only applies to bends or length which only applies to tubing.

The idea being that a number of cells are selected and then they are marked as containing data for an attribute within a class.

Firstly, am I on the wrong lines and secondly, if this approach is right how would I designate a cell or cells to be of a given class?

Edit: Datatable is created from strings in an opened user file containing unformatted data. It is then displayed in a datagrid.

Cimbian
  • 173
  • 2
  • 3
  • 12

2 Answers2

1

The first important thing is to know which way and what technology you want to use, which is the better for your context.

If the only "requirement" is to read some text from database and put that values to an intermediate data object, the consideration to take is:

  1. if the only data access is about reading just that values, it's not suitable to take an "over engineering" solution, for example ORMs are not the best solutions
  2. if it's important to take an elegant way to do, maybe some tiny orms like helpers maybe are good

The considerations could be more, now I will enumerate some tools:

  1. PetaPoco "A tiny ORM-ish thing for your POCOs" there are fine examples and instructions
  2. Massive "Massive is a Single File Database" there are very good examples and it's the fastest way to accomplish what you want to do in an elegant way
  3. SqlDataReaderToObject another faster way to accomplish what you want to do
  4. Extension methods for IDbComannd and IDataReader the fastest and costless solutions

Based on my experience I strongly suggest you a solution based on Massive, no assembly to install, just a code file to include in you solution, but, the fastest way, using datacomnnad and datareader from the point 4, could be a good solution.

Hope this helps.

Hoghweed
  • 1,938
  • 1
  • 16
  • 35
0

I suggest you to use linq to SQL. It is a part of ADO.NET

msdn.microsoft.com for linq to SQL

LINQ to SQL: .NET Language-Integrated Query for Relational Data

Simple LINQ to SQL in C#

Incredible
  • 3,495
  • 8
  • 49
  • 77
sourabh devpura
  • 605
  • 8
  • 25
  • The data is unformatted text until I classify it and can then put it into a proper dataset. – Cimbian Aug 02 '13 at 10:00
  • as i understand your Q. u need an auto code generation . for thet you need learn t4 templates in c# . http://msdn.microsoft.com/en-us/data/gg558520.aspx – sourabh devpura Aug 02 '13 at 10:03
  • Okay, I have just looked at auto-code generation and I don't think this is it. My program will open a text file of 'parts' into a datatable. the user will select cell(s) and then tell the program that those cells contain an attribute (ie. radius). Behind the scenes the program will then build a formatted dataset. – Cimbian Aug 02 '13 at 10:13