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
275 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Visual xHarbour 1 76
wordlen challenge 3 47
wordappend challenge 8 85
c++ reading data from file into two dimensional array 3 27
This is about my first experience with programming Arduino.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

706 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

20 Experts available now in Live!

Get 1:1 Help Now