Link to home
Start Free TrialLog in
Avatar of Moti Mashiah
Moti MashiahFlag for Canada

asked on

Visual basic

Hi guys,

I'm doing some query to get a parameter from SQL.

 Using cmd As New SqlCommand("select * from" + " " + tablen + " " + "where id=@rowid", Basewebpage.Passport.Connection)
            cmd.Parameters.AddWithValue("@rowid", rowid)
            Dim getRow = Convert.ToInt32(cmd.Parameters(0).Value)

        End Using

Open in new window


I have one issue here:
I can't get the value- Dim getRow = Convert.ToInt32(cmd.Parameters(0).Value)
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

You aren't using a stored procedure, so there isn't a "return value".  There is a result of your query, and so to get that, you need to do:

Dim getRow = Convert.ToInt32(cmd.ExecuteScalar());

Open in new window


https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar(v=vs.110).aspx
Avatar of Moti Mashiah

ASKER

Thank you for your answer.
can you just tell me how to pass the let's say column 0 only?

can I do
Dim getRow = Convert.ToInt32(cmd.ExecuteScalar(0))
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore 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
Basically U gave me a good solution but still it doesn't return a value just a boolean it there is data or not and this is good enough foe me.