Easy One:  How do I populate a RichTextBox with a cell from SQL Server?

Posted on 2005-05-02
Last Modified: 2010-04-23
Here is the code that I am using,

        Dim sqlcom1 As SqlCommand = New SqlCommand("SELECT * " & _
                                        "FROM TABEL1 " & _
                                        "WHERE VAR1 = '" & cmb_VAR1.Text & "'")
        Dim reader_recode As SqlDataReader
        reader_recode = sqlcom1.ExecuteReader
        While reader_recode.Read
            rtb_DATA1.Text = reader_recode("DATA1")
        End While

I get an error when using Option Strict On.  If I turn that off, things are fine, but I would like to code this correctly.

Here is the error:

Option Strict On disallows implicit conversions from 'System.Object' to 'String'.

Any ideas?
Question by:tobey1
    LVL 24

    Accepted Solution

    You might try:

    rtb_DATA1.Text = reader_recode("DATA1").ToString
    LVL 8

    Expert Comment

    reader_recode.getvalue(0) replace the 0 with the number of the field u are trying to get. This is really the proper way of using the reader.

    0 example

    say u have a table with the following fields
    field1 field2 field3

    and u want field 2 u would replace 0 to 1


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 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

    11 Experts available now in Live!

    Get 1:1 Help Now