Learn how to a build a cloud-first strategyRegister Now

x
?
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
Medium Priority
?
321 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Progress

810 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