• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

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

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?
1 Solution
Jeff CertainCommented:
You might try:

rtb_DATA1.Text = reader_recode("DATA1").ToString
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


Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now