Read SQLite Field into a variable in VB.net

rwensley
rwensley used Ask the Experts™
on
Greetings,

I need to read a field from a record in SQLite into a variable in VB.net.
Many examples exist for reading into a textbox, combobox, listbox, or datagrid.  But I can not find an example of reading into a variable.

ie.  A = column 1 of the table at row 1 (Column 1 is a BOOLEAN)
B = column 2 of the table at row 1 (Column 2 is a FLOAT)

I have thought of reading the values into an 'invisible' textbox then dealing with them, but this is very sloppy and not the way I want to proceed.

Thanks for the Help,
Ron
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
I am using this code and have verified that the field in the database is a BOOLEAN data type

There are no errors when it runs, however the _bool is always False even when the field value is True

SQLcommand.CommandText = "SELECT fc_calibrated_meter FROM flowcalcs WHERE fc_tag='" & cmbFCTag.Text & "'"
        Dim _bool As Boolean = CType(SQLcommand.ExecuteScalar(), Boolean)
        TextBox1.Text = _bool

Any ideas are welcome
Ron

Author

Commented:
NOTE: These text box is for displaying the value only.  I want the variable -bool to be used elsewhere in the program.
Most Valuable Expert 2012
Top Expert 2014
Commented:
ExecuteScalar can only return numeric values. Try this instead

SQLcommand.CommandText = "SELECT fc_calibrated_meter FROM flowcalcs WHERE fc_tag='" & cmbFCTag.Text & "'"
        Dim dbreader as SqlDataReader = SQLCommand.ExecuteReader
        If dbreader.HasRows Then
           dbreader.Read
           Dim _bool As Boolean = dbreader.item(0)
           TextBox1.Text = _bool.ToString
        End If
        dbreader.close

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial