Solved

I need to convert a dataset that only has one value (one column and one row = a single cell) into a string.

Posted on 2004-09-30
2
285 Views
Last Modified: 2011-09-20
Hello all,

I am trying to populate a text box with a string value from a dataset.  My function can find the appriate field that contains the string that I want.  But i dont know how to extract the string...  

===========================================================================================================


    Function GetFields(byval strTable as String, byval strReferenceColumn as string, byval strReferenceValue as string, byval strReturnColumn as string) as string
       
        'open connection
        Dim connectionString As String = "server='(local)'; trusted_connection=true; database='Clients'"
        Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString)
   
        'build query string
        Dim queryString As String = _
        "SELECT [" & strTable & "].[" & strReturnColumn & "] FROM [" & strTable & "] WHERE ([" & strTable & "].[" & strReferenceColumn & "] = @strReferenceValue)"
       
        'create new sql command
        Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
       
        'add a paramater to the command
        sqlCommand.Parameters.Add("@strReferenceValue", System.Data.SqlDbType.VarChar).Value = strReferenceValue
       
        'open the DB connection
        sqlConnection.Open()
       
                                                                                                                                                     'here is the problem!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                                                                                                                                                     '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                                                                                                                                  'How do I make this reader give mea string of the value that is in the field?
                       
        Dim reader = sqlCommand.ExecuteReader()
        strReturnString = reader.read                                                                                                                     ' <---- this line will fill my text box with "TRUE"
       
        'I have also tried this and if filled my textbox with the actual command
       
        'strReturnString = reader.ToString
       
       
       
        return strReturnString
       
    end function

=======================================================================================================

Thank you,

_TH
0
Comment
Question by:travishaberman
2 Comments
 
LVL 4

Accepted Solution

by:
willcode4coffee earned 500 total points
ID: 12194101
Try this:

strReturnString = reader.Item(0).ToString

-or-
strReturnString = reader.Item("YourColumnName").ToString

M@
0
 

Author Comment

by:travishaberman
ID: 12194217
That is perfect!  Thank you..

-TH
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now