Re: Retrieving row info by Teo
Teo
Tue Jul 15 22:49:20 CDT 2003
Hey David! First of all, thanks so much for helping me with this, I know I
will get to understand it better once this example works. I understood the
Command properties and how to create a command. I did a SQLDBADAPTER,
attached it to my stored procedure and then created a Command, and did all
the renaming and selected it as a StoredProcedure.
Now, I want to call my stored procedure that is like the following
SELECT COUNT(Usuario_ID) FROM Usuario WHERE ......
I have two parameters, @login and @password so based on that, the query will
return 1 or 0 depending whether the user is found or not. Now, this is the
code I have on the OK button on my login form that gets values from my
textboxes and attaches it to the parameters of the stored procedure. Is
there something I am doing wrong cause I keep getting a message that it's
not working. Check the code below.
Dim login As String
Dim password As String
Dim oklogin As Boolean
login = txtlogin.Text
password = txtpassword.Text
Dim callds As String
Dim query As String
query="checklogin"&login,password
callds = checklogin.CommandText(query)
Dim loginresult As Integer
loginresult = checklogin.ExecuteScalar
If loginresult = 0 Then
MsgBox("Usuario no valido, vuelva a intentar...", "", "Usuario no valido")
ElseIf loginresult = 1 Then
MsgBox("Bienvenido a Flight School Professional!", "", "Usuario
Autenticado")
End If
Thanks so much,
Teo
"David Sceppa" <davidsc@online.microsoft.com> wrote in message
news:af874zxSDHA.2316@cpmsftngxa06.phx.gbl...
> Teo,
>
> > what do I need to do to run the Stored procedure
> > and get the results?
>
> Create a Command.
> Set the CommandText to the name of your stored procedure.
> Set CommandType to CommandType.StoredProcedure.
> Append parameters to the Command.
>
> How you execute the Command and check for results will
> depend on how you've constructed the stored procedure and what
> type of results you want to examine.
>
> If your stored procedure returns a resultset, call
> Command.ExecuteReader and fetch the results from the DataReader.
>
> If your stored procedure returns data via output parameters
> and also returns a resultset, call Command.ExecuteReader, fetch
> the results from the reader, close the reader, then check the
> value of your Parameter objects.
>
> If your stored procedure returns data only via output
> parameters, call Command.ExecuteNonQuery and check the value of
> your Parameter objects.
>
> ExecuteScalar is a method that's available on the various
> Command objects (OleDbCommand, SqlCommand, etc.) that can
> simplify your coding. It's designed for queries that return a
> single value, like "SELECT COUNT(*) FROM MyTable WHERE ...". It
> creates, consumes, and closes a DataReader under the covers, and
> returns the first column value for the first row.
>
> I hope this information proves helpful.
>
> David Sceppa
> Microsoft
> This posting is provided "AS IS" with no warranties,
> and confers no rights. You assume all risk for your use.
> © 2003 Microsoft Corporation. All rights reserved.
>