Get the SQL types from a database

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I understand that in VB6 there was a command that let you poll the database
and get the types of the columns (or something similar). I haven't worked in
this language so I am not sure about it, but would anyone know if there is
something similar in C#?

My idea is to create a data access layer and would like to just pass in
strings for the parameters and let the data access layer take care of all
conversions.

Does anyone know if this is possible?
 
HI,

Don't know if this would help, but here is a portion of a class that i have
used before. You can adapt to your needs. and you can call the method what
ever you need, passing what ever values.

internal void GetControlValue(DataRow row, DataColumn dataColumn, string
value, bool required, List<string> ErrorList)
{
if (string.IsNullOrEmpty(value) && dataColumn.AllowDBNull)
row[dataColumn] = DBNull.Value;
else
{
if (dataColumn.DataType == typeof(string))
{
row[dataColumn] = value;
}
else if (dataColumn.DataType == typeof(int))
{
row[dataColumn] = int.Parse(value);
}
else if (dataColumn.DataType == typeof(decimal))
{
row[dataColumn] = decimal.Parse(value);
.....
.....
.....


Robert
 
cashdeskmac said:
I understand that in VB6 there was a command that let you poll the database
and get the types of the columns (or something similar). I haven't worked in
this language so I am not sure about it, but would anyone know if there is
something similar in C#?

My idea is to create a data access layer and would like to just pass in
strings for the parameters and let the data access layer take care of all
conversions.

Does anyone know if this is possible?

It is possible.

If you tell us what database, then we can tell you how.

Arne
 
That's an interesting concept, but it might be "missing the mark" on how /
what a Data Access Layer might do. Before you get started, make sure you
aren't reinventing the wheel. Check out the SqlHelper (DAAB v2) class for
starters, and if you want to see something more sophisticated, check out the
Enterprise Library v 3.1 - each has full source code.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
 
Many thanks, Peter, that looks very interesting. I am going to play with
that for a few days and will let you all know if it doesn't provide a
solution to the problem.

:

That's an interesting concept, but it might be "missing the mark" on how /
what a Data Access Layer might do. Before you get started, make sure you
aren't reinventing the wheel. Check out the SqlHelper (DAAB v2) class for
starters, and if you want to see something more sophisticated, check out the
Enterprise Library v 3.1 - each has full source code.
 
Hi,
I understand that in VB6 there was a command that let you poll the
database and get the types of the columns (or something similar). I
haven't worked in this language so I am not sure about it, but would
anyone know if there is something similar in C#?

My idea is to create a data access layer and would like to just pass
in strings for the parameters and let the data access layer take care
of all conversions.

Does anyone know if this is possible?

Instead of "strings", it might be better to use "objects", as that will save
you from a lot of conversions (what date is "01/02/03"?)

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top