|
 |
aspx thread: Check to see if a record exists
Message #1 by "charles baldo" <charlesbaldo@h...> on Tue, 22 May 2001 20:08:36
|
|
Hello,
How can I see if a record exists in my database? Using Dataset technology
I will still have to go back to the server. (Cant load the entire database
in the dataset). Can I just use the old recordset technology?
Chuck
Message #2 by =?iso-8859-1?Q?Fredrik_Norm=E9n?= <fredrik.normen@e...> on Wed, 23 May 2001 08:16:26 +0200
|
|
Hi,
If you use stored procedure you can use output parameters to return a value
instead of returning a result set with data.
Here is an example who you can ask for a user and if it exist you will have
the users fullname returned:
SQLConnection myConnection = new SQLConnection("<- Your Connextion String
here ->");
SQLCommand myCommand = new SQLCommand("sp_login", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
SQLParameter parameterUser = new SQLParameter("@User",
SQLDataType.NVarChar, 100);
parameterUser.Value = "admin";
myCommand.Parameters.Add(parameterUser);
SQLParameter paramUserName = new SQLParameter("@UserName",
SQLDataType.NVarChar, 100);
paramUserName.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(paramUserName);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
return (String)paramUserName.Value;
The Stored procedure will look like:
CREATE Procedure sp_login
(
@User nvarchar(100),
@UserName nvarchar(100) OUTPUT
)
AS
SELECT
@UserName = FullName
FROM
Users
WHERE
UserName=@User
IF @@Rowcount < 1
SELECT @UserName = ""
GO
I hope this will give you some ideas.
Best Regards,
Fredrik Normén
-----Original Message-----
From: charles baldo [mailto:charlesbaldo@h...]
Sent: den 22 maj 2001 20:09
To: ASP+
Subject: [aspx] Check to see if a record exists
Hello,
How can I see if a record exists in my database? Using Dataset technology
I will still have to go back to the server. (Cant load the entire database
in the dataset). Can I just use the old recordset technology?
Chuck
|
|
 |