Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
(Sorry for my bad english)
I want to convert a data extracted from SQL server (For example a INT), and Print that with a MsgBox in VB.NET
For example, in a Table I had the column Age, I Selected just the Age of one person, and I want to convert that to an Variable that I Dim in VB...
Maybe if you see what I tried you understand what I want
Thanks!

What I have tried:

Dim da As New OleDbDataAdapter("SELECT rank FROM Clientes WHERE user='" & TextBox1.Text & "' AND password='" & TextBox2.Text & "';", cn)
        Dim ds As New DataSet

        da.Fill(ds, "Clientes")

        With DataGridView1
            .DataSource = ds.Tables("Clientes")
            .Refresh()
        End With

        MsgBox(Convert.ToInt16(da)) 'HERE I WANT TO PRINT THE RESULT OF THE SELECT
Posted
Updated 6-May-17 8:15am

1 solution

Assuming the query is meant to return a single value - and if it doesn't, you need to change it so it does - then don't use a data adapter at all.
Instead, use an OleDbCommand, and call ExecuteScalar: OleDbCommand.ExecuteScalar Method (System.Data.OleDb)[^] - it returns the single value directly, and you can just cast it to a number and do what you want with it.
 
Share this answer
 
Comments
Member 13178411 6-May-17 14:45pm    
Thanks!
That Works :D
OriginalGriff 6-May-17 15:49pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900