Click here to Skip to main content
15,885,891 members

Prepopulate Page on Page Load

ESTHERM asked:

Open original thread
Good day

Please help Im trying to get my form prepopulated when my page loads but i keep on getting this error: Procedure or function 'sp_Getuserinfo' expects parameter '@EmployeeNumber', which was not supplied.

IM I CALLING MY FUNCTION CORRECTLY ON PAGE LOAD?

MY STORE PROCEDURE:

USE [Portal]
GO
/****** Object: StoredProcedure [dbo].[sp_Getuserinfo] Script Date: 01/30/2013 07:11:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_Getuserinfo]
@EmployeeNumber varchar(30)

AS
BEGIN
-- [dbo].[sp_Getuserinfo] 'F3519554'
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here

SELECT EmployeeNumber
,CostCenter
,BusinessArea
,Telephone
,Category
,SubCategory

FROM [Portal].[dbo].[TaskRequest]
WHERE ID = (SELECT MAX(ID) FROM [Portal].[dbo].[TaskRequest]
WHERE EmployeeNumber = @EmployeeNumber)
END

MY CODE ON.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{

lblError.Visible = false;
// lblErrorConfirm.Visible = false;
btnSubmit.Enabled = true;
if (!IsPostBack)
{

//this.PopulateUserDetails();
#if DEBUG
ClearApplicationCache();

#endif



#region Max. file size message
System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
HttpRuntimeSection section = config.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
double maxFileSize = Math.Round(section.MaxRequestLength / 1024.0, 1);
spUploadInfo.InnerText = spUploadInfo.InnerText + string.Format("Make sure the total file size is under {0:0.#} MB.", maxFileSize);
#endregion Max. file size message

lblLogin.Text = Page.User.Identity.Name;


if (SessionId == 1005)
{
SessionId = Login();
}




int statusId = ws.ServerStatus(SessionId);
string errorMessage = string.Empty;
switch (statusId)
{
case 1:
lblError.Visible = true;
btnSubmit.Enabled = false;
lblError.Text = "An error occurred while retrieving the session
Error details:
The service desk server is not available.";
errorMessage = "User: " + Page.User.Identity.Name + "\n
" + lblError.Text;

FitWebDev.Library.Logging.Log.WriteToEvent(errorMessage, System.Diagnostics.EventLogEntryType.Error, eventLogSource, "Application");
Session.Remove("sid");
break;
case 0:
#region Get Category and employee detail

string employeeNumber = Page.User.Identity.Name.Substring(Page.User.Identity.Name.LastIndexOf("\\") + 1);

lblEmployeeNumber.Text = employeeNumber;



//Pre_Populating Cost Center, Tel and Business Area // 25 JAN 2013
try
{

using (portalCnn)
{
portalCnn.Open();
using (SqlCommand command = new SqlCommand("sp_Getuserinfo", portalCnn))
{

SqlDataReader reader = command.ExecuteReader();
//SqlDataReader reader = GetUserDetails(lblEmployeeNo);

while (reader.Read())
{

lblEmployeeNumber.Text = (String)reader["EmployeeNumber"];
lblCC.Text = (String)reader["CostCenter"];
txtTelephone.Text = (String)reader["Telephone"];
ddlBusinessArea.Text = (String)reader["BusinessArea"];
ddlCategory.Text = (String)reader["Category"];
ddlSubCategory.Text = (String)reader["SubCategory"];

}
}
}
FUNCTION//Pre_Populating Cost Center, Tel and Business Area : Date:29/01
private SqlDataReader PopulateUserDetails(string EmployeeNo)
{

using (portalCnn)
{

SqlCommand cmd = new SqlCommand("sp_Getuserinfo", portalCnn);

cmd.CommandType = System.Data.CommandType.StoredProcedure;
SqlParameter param = new SqlParameter("@EmployeeNumber", SqlDbType.Int);
param.Direction = ParameterDirection.InputOutput;
param.Value = lblEmployeeNumber.Text;
cmd.Parameters.Add(param);
cmd.Parameters.AddWithValue("@EmployeeNumber", EmployeeNo);

cmd.Parameters.Add("@EmployeeNumber", System.Data.SqlDbType.VarChar, 30);
param.Value = lblEmployeeNumber.Text;

SqlDataReader reader = cmd.ExecuteReader();
// reader.SelectCommand = cmd;

portalCnn.Open();
return cmd.ExecuteReader();


}
}


PLEASE ASSIST I DONT KNOW WHAT IM DOING WRONG CAUSE WHEN I TEST THE STORE PROCEDURE IS WORKING FINE ON THE DATABASE :-(
Tags: C#

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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