473,394 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Get the SQL types from a database

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?
Sep 2 '07 #1
5 1240
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<stringErrorList)
{
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" <ca*********@discussions.microsoft.comwrote in message
news:D9**********************************@microsof t.com...
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?
Sep 2 '07 #2
cashdeskmac wrote:
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
Sep 2 '07 #3
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

"cashdeskmac" wrote:
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?
Sep 2 '07 #4
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.

"Peter Bromberg [C# MVP]" wrote:

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.

Sep 3 '07 #5
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
Sep 3 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: nospam | last post by:
I got three (3) files (1) Untitled.aspx (2) Untitled.aspx.1.cs (3) Untitled.aspx.2.cs These three files must be used together to make file #1, Untitled.aspx, page work via J.I.T. when the...
11
by: theshowmecanuck | last post by:
As a matter of academic interest only, is there a way to programmatically list the 'c' data types? I am not looking for detail, just if it is possible, and what function could be used to...
20
by: GS | last post by:
The stdint.h header definition mentions five integer categories, 1) exact width, eg., int32_t 2) at least as wide as, eg., int_least32_t 3) as fast as possible but at least as wide as, eg.,...
4
by: Popoxinhxan | last post by:
Hi guy, i just wondering that is it posible to convert the array of string to enum types dynamically, for example i get the list of countries name from database and would like to convert all of...
0
by: Larry Lard | last post by:
There seems to be something a bit lacking in the way the dataset designer thing deals (or rather doesn't) with nullable fields in VS2005. Maybe it's cos I'm using VB2005 Express (which is variously...
11
by: mesut demir | last post by:
Hi All, When I create fields (in files) I need assign a data type like char, varchar, money etc. I have some questions about the data types when you create fields in a file. What is the...
5
by: MadDiver | last post by:
Guys, I need to create an application that handles several product types/ categories. Each product type can have totally different fields to describe it. For instance a car would have Year,...
0
by: jehugaleahsa | last post by:
Try this instead: // T - the type you are attempting to retrieve. // o - the data that you want to turn into a T T get<T>(object o) { // handle nulls - turns Nullables into null, reference...
6
by: Tony Johansson | last post by:
Hello! I'm reading in a book called Visual C# 2005. In the chapter about Generics there ia a section about Nullable types. Here is the text that isn't complete true I think. It says: "You...
3
by: Dean Slindee | last post by:
Need to write a standalone application that processes data once per day. Looking for the application program types available that would satisfy these requirements: Requirements: 1. Unattended...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.