Groups > Databases > MySQL for ASP.NET > Re: reate a sq procedure




reate a sq procedure

reate a sq procedure
Fri, 22 Feb 2008 04:22:50 +000
i want to create a sq procedure for a table called login in whic 2 fields are
there user id and pwd i want to fetch the user id and pwd from login table using
sql store procedure in text box asp.net, please help me with step by step code
foe sql procedure and asp.net code with c#
Post Reply
Re: reate a sq procedure
Fri, 22 Feb 2008 06:04:29 +000
As starters, here are two links to give you some background on SQL:

W3 Schools SQL Primer: http://www.w3schools.com/sql/default.asp

SQL Server Books Online Download:
http://msdn2.microsoft.com/en-us/library/ms130214.aspx

Here is a quick mock up of the stored procedure:

 

CREATE PROCEDUREsp_GetLoginInfo
@user_id varchar(10),
@password varchar(10) -- Update these two fields based off of db schemaAS
SET NOCOUNT ON

SELECT user_id, password FROM LOGIN WHERE

You will want to use a SqlCommand with a  SqlDataReader to obtain these values. 


SqlCommand cmd = new SqlCommand("sp_GetLoginInfo", "<your
connection string");
cmd.Parameters.AddWithValue("@user_id", strUserId);
cmd.Parameters.AddWithValue("@password", strPassword);

cmd.Connection.Open();

SqlDataReader dr = cmd.ExecuteReader();

while(dr.Read())
{
   txtUserId.Text = dr["user_id"].ToString();
   txtPassword.Text = dr["password"].ToString();
}

cmd.Connection.Close();

Hope this provides some insight.

- Jesse
Post Reply
Re: reate a sq procedure
Fri, 22 Feb 2008 17:25:52 +000
Dear Jesse,

Thanks a lot for helping me in the sql procedure also i want to ask you that in
my table i have data i.e user names and pwd

if i put 2 text boxes in my webpage where the user enters the userid and
password and i want to check whether the user has enter the correct pwd and
userid thru sql procedure and c# code, please help me in this code also
Post Reply
Re: reate a sq procedure
Sat, 23 Feb 2008 04:43:48 +000
No problem at all.  The code to verify the returned results against what was
input by the user in the text boxes would be:  

//Using the data reader from my previous postif(txtPassword.Text !=
dr["password"].ToString())
{
   //TODO: Notify user on form that their login failed.
}

 
 Hope this helps some more!

- Jesse
Post Reply
Re: reate a sq procedure
Sun, 24 Feb 2008 00:18:37 +000
HI Jesse ,

 Again thanks a lot for ur quick resolution towards my query.

 Can we fetch(obtain the values) the data from store procedure without
SqlDatareader and also compare(pass the calues to store procedure) the values
that has been entered as user id and password,.

In this also i 100% belive u will help with complete code as earlier.

Awaiting your response.

Thanks in Advance.
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact