Tuesday, February 21, 2012

Returning database schemas

Hi, I am storing information being sent to me weekly into a ms sql
database. The one twist I am running into is that later down the line
the information I recieve may require more columns, or columns might
be renamed so having a static database call is out of the question. I
was using mysql but for certain reasons switched to ms sql 2000.
Currently before ms sql, I query the database for show fields which
returns all the database data such as type, column name, etc... then I
use a giant if statement structure to deal with matching and
converting data from my users display to the information into the
database.

So my first question is how do I either query or using datatypes built
into C# return information about a tables setup. I was hoping there
was some sort of table array object which could be returned with names
and types, if not then just an sql statement return.

My second question is I have user data which needs to be displayed
differently then the database raw data, how do I use a C# dataset, and
convert it's column data into my raw database data without having to
create raw insert and update sql strings myself? I would really like
to use the sort of automatic update features of the dataset.

Lastly am I going about this the wrong way? Are there other ways to
map & convert datatypes between a dataset column and a table column.sailent@.hotmail.com (Craig) wrote in message news:<35c0cc31.0405062101.7a469a83@.posting.google.com>...
> Hi, I am storing information being sent to me weekly into a ms sql
> database. The one twist I am running into is that later down the line
> the information I recieve may require more columns, or columns might
> be renamed so having a static database call is out of the question. I
> was using mysql but for certain reasons switched to ms sql 2000.
> Currently before ms sql, I query the database for show fields which
> returns all the database data such as type, column name, etc... then I
> use a giant if statement structure to deal with matching and
> converting data from my users display to the information into the
> database.
> So my first question is how do I either query or using datatypes built
> into C# return information about a tables setup. I was hoping there
> was some sort of table array object which could be returned with names
> and types, if not then just an sql statement return.
> My second question is I have user data which needs to be displayed
> differently then the database raw data, how do I use a C# dataset, and
> convert it's column data into my raw database data without having to
> create raw insert and update sql strings myself? I would really like
> to use the sort of automatic update features of the dataset.
> Lastly am I going about this the wrong way? Are there other ways to
> map & convert datatypes between a dataset column and a table column.

Have you looked at the INFORMATION_SCHEMA views?
INFORMATION_SCHEMA.COLUMNS has details about every column, including
data type etc. Or there is sp_help, but it returns multiple result
sets, so it may not be so easy to work with.

Regarding your dataset questions, you might get a better response in a
..Net development group.

Simon

No comments:

Post a Comment