Last post Jan 04, 2017 11:36 PM by ma701ss
Jan 04, 2017 01:50 AM|ma701ss|LINK
I'm trying to use this code but don't understand what ExecuteScalar does despite googling.
userId is returned from a stored procedure. Could someone please clarify?
Protected Sub ValidateUser(sender As Object, e As EventArgs)
Dim userId As Integer = 0
Dim constr As String = ConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("Validate_User")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = con
userId = Convert.ToInt32(cmd.ExecuteScalar())
Select Case userId
Login1.FailureText = "Username and/or password is incorrect."
Login1.FailureText = "Account has not been activated."
Jan 04, 2017 04:00 AM|a2h|LINK
but don't understand what ExecuteScalar does despite googling
Execute scalar is used when the result of query return a single resultset. Execute scalar run the query, and returns the first column of the first row in the result set returned by the query.
You can find a good explanation in this link
Jan 04, 2017 01:55 PM|rrrsr7205|LINK
Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
Jan 04, 2017 02:31 PM|PatriceSc|LINK
Or just use the documentation for this kind of basic question. From
"Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored."
Jan 04, 2017 11:36 PM|ma701ss|LINK
Thanks, and honestly I did Google this several times but obviously didn't find the right page to explain it.