select stored procedure

  • Thread starter Thread starter nicholas
  • Start date Start date
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()
 
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()
|
|
|
 
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
 
Back
Top