Click here to Skip to main content
16,004,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
cmd.CommandText = "SP_user_verifi";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@Name", nameforlogin.Text);
            cmd.Parameters.AddWithValue("@Password", pwdforlogin.Text);


            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            da.SelectCommand = cmd;
            da.Fill(ds);

if (ds != null && ds.Tables.Count > 0)
           {
               string status = ds.Tables[0].Rows[0][0].ToString();
               if (status == "yes")



                  Session["Id"]             = ds.Tables[1].Rows[0]["id"].ToString();
                  Session["nameforlogin"]   = ds.Tables[1].Rows[0]["Name"].ToString();
                  Session["pwdforlogin"]    = ds.Tables[1].Rows[0]["Password"].ToString();


response.redirect("test.aspx");




and my stored proc is

SQL
ALTER proc [dbo].[SP_user_verifi]
(
@Name nvarchar(MAX),
@Password nvarchar(MAX)
 
)
as
begin
if exists (select * from tb_userlogin where Name=@Name and Password=@Password )
begin


select 'yes' as status
end
else
begin

select 'no' as status
end
end

in the above code i have error like cannot find table 1 at this line


Session["Id"] = ds.Tables[1].Rows[0]["id"].ToString();

can any one help me..

Thanks and Regards
Posted
Updated 16-Sep-13 19:36pm
v3
Comments
Dholakiya Ankit 17-Sep-13 1:36am    
What is the error?

I think the problem wasn't caused by the session variable.

Check this line of code, I think if you change this it will work well:
C#
//Session["Id"] = ds.Tables[1].Rows[0]["id"].ToString();
Session["Id"] = ds.Tables[0].Rows[0]["id"].ToString();
 
Share this answer
 
HI,
From stored procedure you have only one select statement which is returning. So, It returns Table count 1.
Try this.
cmd.CommandText = "SP_user_verifi";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", nameforlogin.Text);
cmd.Parameters.AddWithValue("@Password", pwdforlogin.Text);
 
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
da.SelectCommand = cmd;
da.Fill(dt);
if (dt!= null && dt.Rows.Count > 0)
{
     Session["Id"] = dt.Rows[0]["id"].ToString();
     //remaining code
}

or
cmd.CommandText = "SP_user_verifi";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", nameforlogin.Text);
cmd.Parameters.AddWithValue("@Password", pwdforlogin.Text);
 
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataTable();
da.SelectCommand = cmd;
da.Fill(ds);
if (ds!= null && ds.Tables.Count > 0)
{
     Session["Id"] = ds.Tables[0].Rows[0]["id"].ToString(); // since it returns only 1 table
     //remaining code
}

Hope it helps you.
Thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900