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
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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?
Simple Linear Regression
Introduction to Processes

724 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