select stored procedure

N

nicholas

I want to check if a userlogin already exists, so this is what i did...but
it is not working and I just can't get it to work. Must be something
stupid, but I don't see it ;-)
(I don't get any error, it just doesn't work)

STORED PROCEDURE:
==================

CREATE PROCEDURE sp_select_userlogin
@userlogin nvarchar
AS
SELECT userlogin FROM tbl_users WHERE userlogin = @userlogin
GO


CODE ON ASPX PAGE on mybutton click :
===============================
'define where the connectionstring is here:
Dim MyConnectionString as String =
ConfigurationSettings.AppSettings("ConnectionString")
Dim ObjReader as SQLDataReader

'make the connection
Dim MyConnection as New
SQLConnection(MyConnectionString)

Dim ObjCmd as SQLCommand= New
SQLCommand("sp_select_userlogin",MyConnection)
ObjCmd.CommandType = CommandType.StoredProcedure



' Set up parameter for stored procedure
ObjCmd.Parameters.Add(New SqlParameter("@userlogin",
SqlDbType.NVarChar, 50))
ObjCmd.Parameters("@userlogin").Value = userlogin.text


Dim daLogins As New SqlDataAdapter(ObjCmd)
Dim dsLogins As New DataSet()


If dsLogins.Tables.Count = 0 Then
lbl_user_allready_exists.visible = false
Else
lbl_user_allready_exists.visible = true
End If

ObjCmd.Connection.Close()
 
B

bruce barker

even if there are no users, the result set meta data is returned, so you
need to test the row count not the table count. (i assume you have code to
actually run the query)

try:

lbl_user_allready_exists.visible = dsLogins.Tables(0).Rows.Count >
0

-- bruce (sqlwork.com)


| I want to check if a userlogin already exists, so this is what i did...but
| it is not working and I just can't get it to work. Must be something
| stupid, but I don't see it ;-)
| (I don't get any error, it just doesn't work)
|
| STORED PROCEDURE:
| ==================
|
| CREATE PROCEDURE sp_select_userlogin
| @userlogin nvarchar
| AS
| SELECT userlogin FROM tbl_users WHERE userlogin = @userlogin
| GO
|
|
| CODE ON ASPX PAGE on mybutton click :
| ===============================
| 'define where the connectionstring is here:
| Dim MyConnectionString as String =
| ConfigurationSettings.AppSettings("ConnectionString")
| Dim ObjReader as SQLDataReader
|
| 'make the connection
| Dim MyConnection as New
| SQLConnection(MyConnectionString)
|
| Dim ObjCmd as SQLCommand= New
| SQLCommand("sp_select_userlogin",MyConnection)
| ObjCmd.CommandType = CommandType.StoredProcedure
|
|
|
| ' Set up parameter for stored procedure
| ObjCmd.Parameters.Add(New SqlParameter("@userlogin",
| SqlDbType.NVarChar, 50))
| ObjCmd.Parameters("@userlogin").Value = userlogin.text
|
|
| Dim daLogins As New SqlDataAdapter(ObjCmd)
| Dim dsLogins As New DataSet()
|
|
| If dsLogins.Tables.Count = 0 Then
| lbl_user_allready_exists.visible = false
| Else
| lbl_user_allready_exists.visible = true
| End If
|
| ObjCmd.Connection.Close()
|
|
|
 
L

Lowell Heddings

nicholas said:
Dim daLogins As New SqlDataAdapter(ObjCmd)
Dim dsLogins As New DataSet()


Don't you need to add this line right below that:

daLogins.Fill(dsLogins)

Otherwise you aren't filling the dataset, so any check against the
tables won't work.

Lowell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top