0

I have got 2 asp pages. Firstly i get logged in through log in page and 2nd page is home page where i got few buttons of some tasks. Along with that i got user details which consists of FULLNAME,ADDRESS,CELL NUMBER,BLOOD GROUP and EMAILID, this should be displayed dynamically in their particular labels from DATABASE once the user logs in using his username and password.

I have written Query for this within the GetLoginDetails Stored Procedure. I have to display Employee Name,his Last Login Date,Time etc. once his log in and enters home page in the same way i should get user details.

 ALTER PROCEDURE [dbo].[GetLastLogin]

 @LoggedInUser nvarchar(50),
 @FullName nvarchar(50),
 @Address nvarchar(50),
 @MobileNumber bigint,
 @EmailID nvarchar(50),
 @BloodGroup nvarchar(50),
 @EmpName nvarchar(50)

 As

 Declare @LastLogin int

 Set @LastLogin = (Select MAX(AccessID)from dbo.ACCESS_INFO where Flag = 1)

 Select Access_Date, Access_Time from dbo.ACCESS_INFO where LoggedInUser = @LoggedInUser     and AccessID = @LastLogin

 Update dbo.EmployeeData 
 Set Empname = @EmpName
 where FullName = @FullName and Address = @Address and MobileNumber = @MobileNumber and     EmailID = @EmailID and BloodGroup = @BloodGroup ;

im getting error saying tht ("Procedure or function 'GetLastLogin' expects parameter '@FullName', which was not supplied.") please help me out

back end code

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Username"] != null)
        {
            try
            {
                MTMSDTO objc = new MTMSDTO();

                LblLogdInUser.Text = Session["EmpName"].ToString();
                LblUser.Text = Session["Username"].ToString();


                objc.LoggedInUser = LblUser.Text;
                DataSet laslogin = obj.GetLastLogin(objc);
                DataView LasLogin = new DataView();
                LasLogin.Table = laslogin.Tables[0];
                GrdLasLogin.DataSource = LasLogin;
                GrdLasLogin.DataBind();

                if (!IsPostBack)
                {
                    int lastlog = GrdLasLogin.Rows.Count;
                    if (lastlog == 0)
                    {
                        LblLastLoginD.Text = "This is your First Login";

                        DateTime today = System.DateTime.Now.Date;
                        LblToday.Text = today.ToString();
                        LblTime.Text = System.DateTime.Now.ToLongTimeString();

                        objc.LoggedInUser = LblLogdInUser.Text;
                        objc.AccessDate = Convert.ToDateTime(LblToday.Text);
                        objc.AccessTime = Convert.ToDateTime(LblTime.Text);
                        objc.AccessStatus = "New Login";
                        objc.AccessFlag = 1;

                        int accessinfo = obj.InsertAccessInfo(objc);
                    }

                    else
                    {
                        LblLastLoginD.Text =  Convert.ToDateTime(GrdLasLogin.Rows[0].Cells[0].Text).ToString("dd/MMM/yyyy");
                        LblLastLoginT.Text = GrdLasLogin.Rows[0].Cells[1].Text;

                        DateTime today = System.DateTime.Now.Date;
                        LblToday.Text = today.ToString();
                        LblTime.Text = System.DateTime.Now.ToLongTimeString();

                        objc.LoggedInUser = LblLogdInUser.Text;
                        objc.AccessDate = Convert.ToDateTime(LblToday.Text);
                        objc.AccessTime = Convert.ToDateTime(LblTime.Text);
                        objc.AccessStatus = "New Login";
                        objc.AccessFlag = 1;

                        int accessinfo = obj.InsertAccessInfo(objc);
                    }

                    LblFname.Visible = true;
                    LblAdd.Visible = true;
                    LblMnum.Visible = true;
                    LblMailID.Visible = true;
                    LblBGroup.Visible = true;
                }
            }

            catch (Exception ex)
            {
                Response.Redirect("ERROR.aspx");
                Session.Abandon();
            }

        }

        else
        {
            Response.Redirect("~/Login.aspx");
        }

        Response.CacheControl = "no-cache";

    }
Rao
  • 150
  • 4
  • 11
  • 1
    How are you calling it in your ASP.NET code? the error message is correct - you need to supply values for the parameters; so... are you doing that? – Marc Gravell Jun 20 '13 at 12:53
  • Need to see the code that calls this sp. – Steve Jun 20 '13 at 12:53
  • Can you include your calling code? This error indicates that you didn't pass in all of the parameters. – BenR Jun 20 '13 at 12:53
  • the problem is in your asp.net code – Arif YILMAZ Jun 20 '13 at 12:54
  • Is FullName a required field in your database? – CLockeWork Jun 20 '13 at 12:54
  • 1
    welll im using labels to display it. so how to call parameters for labels – Rao Jun 20 '13 at 12:56
  • 1
    yeah sure will post my code... welll i was thnking that my store procedure isnt working fine – Rao Jun 20 '13 at 12:57
  • 1
    yeah full name is required field. depending on the Employee Name when the employee logs in the user details should get populated – Rao Jun 20 '13 at 12:59
  • 1
    With your edit, all of the interesting details are in the method call: `DataSet laslogin = obj.GetLastLogin(objc);` - so - how is that defined? – Marc Gravell Jun 20 '13 at 13:04
  • 1
    im calling d stored procedure with that.. within that GetLoginDetails i have written the query for the details which i need to get populated – Rao Jun 20 '13 at 13:07

2 Answers2

2

The error message makes it clear that you need to supply values for the parameter FullName. So, if you aren't already doing that, then go do that. The only complication here is null values; a string can be null, but to specify that in ADO.NET you need to pass DBNull.Value; if you use null the parameter is not included. This means you end up with code like:

cmd.Parameters.AddWithValue("FullName", (object)fullName ?? DBNull.Value);

Ugly, but it works.

Alternatively, many helper utilities will do this for you. So with "dapper":

var lastAccess = conn.Query<AccessInfo>("GetLastLogin",
          new { LoggedInUser = cn, FullName = fullName, /* snipped */ },
          commandType: CommandType.StoredProcesdure).FirstOrDefault();
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • 1
    i have edited my question along with back end code please go through with it. – Rao Jun 20 '13 at 13:03
  • 1
    @Suraj everything that matters is inside `DataSet laslogin = obj.GetLastLogin(objc);` – Marc Gravell Jun 20 '13 at 13:05
  • 1
    sorry guys it was related to back end coding part not with the stored procedure and i sorted it out.. had o use grid view and then displaying it.. and it was accepting the null values... – Rao Jun 25 '13 at 05:39
0

The problem is not in your SQL. It's in your calling function in asp. You are not sending the fullname parameter to SQL server correctly. Check out this question for an example on how to send parameters. Call a stored procedure with parameter in c#

Community
  • 1
  • 1
John Tseng
  • 6,262
  • 2
  • 27
  • 35