Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Get the SQL types from a database

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cashdeskmac - 02 Sep 2007 20:04 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.