[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register 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
?
319 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn different types of Android Layout and some basics of an Android App.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Starting up a Project

649 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