Link to home
Start Free TrialLog in
Avatar of kkbenj
kkbenj

asked on

VB SQL Display data type of a field

Is there a way to display the data type of a field that I am displaying on a VB form?

I am retrieving data correctly from a SQL table and displaying it on a form.  I just want one more text box, disabled but visable, to show it's data type.

During the SQL select, is there a way to retrieve that information?
Private Sub lstGuiParm_Click()
    Dim fsCmd As String

    fsCmd = ""
    fsCmd = fsCmd & "SELECT  ParmNm, StatusCd, DefaultParmValue "
    fsCmd = fsCmd & "FROM    GuiParmList "
    fsCmd = fsCmd & "WHERE   ParmNm = '" & lstGuiParm.Text & "'"

    Set goRecSet = goConn.Execute(fsCmd)
        While Not goRecSet.EOF
            txtParmNmGui.Text = goRecSet("ParmNm")
            txtStatusGui.Text = goRecSet("StatusCd")
            txtDefaultParmGui.Text = goRecSet("DefaultParmValue")
            goRecSet.MoveNext
        Wend
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Daniel Wilson
Daniel Wilson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
what is the definition of GuiParmList? does it contain the table and column names? if so a query like the one below may help you...
Private Sub lstGuiParm_Click()
    Dim fsCmd As String

    fsCmd = ""
	fsCmd = fsCmd & "SELECT  ParmNm, StatusCd, DefaultParmValue, T.name "
    fsCmd = fsCmd & "FROM    GuiParmList G "
    fsCmd = fsCmd & "INNER JOIN sys.sysobjects O ON G.tableName = O.name "
    fsCmd = fsCmd & "INNER JOIN sys.syscolumns C ON ON O.id = C.id AND C.name = G.columnName "
    fsCmd = fsCmd & "INNER JOIN sys.systypes T ON C.xtype = T.xtype "    
    fsCmd = fsCmd & "WHERE   ParmNm = '" & lstGuiParm.Text & "'"
	
	Set goRecSet = goConn.Execute(fsCmd)
        While Not goRecSet.EOF
            txtParmNmGui.Text = goRecSet("ParmNm")
            txtStatusGui.Text = goRecSet("StatusCd")
            txtDefaultParmGui.Text = goRecSet("DefaultParmValue")
			txtDataType.text = goRecSet("name")
            goRecSet.MoveNext
        Wend
End Sub

Open in new window

Avatar of kkbenj
kkbenj

ASKER

DanielWilson - I tried both:
txtMyType.text = goRecSet("ParmNm").Type
and
txtMyType.text = LTrim(Str(goRecSet("ParmNm").Type)) (per the example on the MS site)

but both display 200, rather than STRING.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kkbenj

ASKER

DanielWilson, thank you for the clarification.

tigin44, I get Invalid column name G.tableName when using the inner joins.
Avatar of Mike McCracken
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.