Link to home
Start Free TrialLog in
Avatar of tobey1
tobey1Flag for United States of America

asked on

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
        reader_recode.Close()

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?
ASKER CERTIFIED SOLUTION
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bman9111
bman9111

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