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?
Robert Bravery - 02 Sep 2007 20:12 GMT
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
> Hi,
>
[quoted text clipped - 10 lines]
>
> Does anyone know if this is possible?
Arne Vajhøj - 02 Sep 2007 21:05 GMT
> 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
[quoted text clipped - 6 lines]
>
> Does anyone know if this is possible?
It is possible.
If you tell us what database, then we can tell you how.
Arne
Peter Bromberg [C# MVP] - 02 Sep 2007 21:14 GMT
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
> Hi,
>
[quoted text clipped - 8 lines]
>
> Does anyone know if this is possible?
cashdeskmac - 03 Sep 2007 13:36 GMT
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.
Hans Kesting - 03 Sep 2007 14:12 GMT
> Hi,
>
[quoted text clipped - 8 lines]
>
> 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