Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining SQL Server datetime

Status
Not open for further replies.

Trancedified

Programmer
Joined
Apr 28, 2004
Messages
6
Location
US
Hello,

I have a listbox w/ names of SQL Server 2000 fields loaded into it.
I looped through the listbox to include square brackets [ ] incase the fields have a blank.

Here is my code:

Code:
Dim i As Integer 
strSQL = "SELECT Toc.Name AS [Document Name], " 
                For i = 0 To lstSelection.Items.Count - 1 
                    lstSelection.SelectedIndex = i 'Read through list box 
                        strSQL &= "[" & lstSelection.Items(i).ToString & "]" & ", " 
       
                Next 
               'Removes the last comma 

                strSQL = strSQL.Substring(0, strSQL.Length - 2)
                strSQL &= " FROM TD4"

Is there a way to tell which field is a SQL Server datetime field automatically then grab that field and CONVERT it with:

Code:
strSQL &= "CONVERT(VARCHAR(10), 101) AS " 'Whatever the datetime field is
(That cuts off the time in the field)

Thanks!

Chris
 
Listboxes can contain more than just string values -- the list is actually a list of Objects (big O).

This means that you can write a class that describes a SQL Server field ... including it's datatype, and use several of them to populate your list (you would override the ToString method).

When you concatenate your SQL from the selected field in the listbox, the selecteditem property would return your field object, and you'd have your datatype.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top