本文介绍了预填充页面加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天



请帮助我试图在我的页面加载时预先填充表格,但我继续收到此错误: 程序或函数''sp_Getuserinfo''需要参数''@EmployeeNumber'',这是未提供的。



我正确地调用我的功能在页面加载?



我的商店程序:



USE [Portal ]

GO

/ ******对象:StoredProcedure [dbo]。[sp_Getuserinfo]脚本日期: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以防止额外的结果集来自

- 干扰SELECT语句。

SET NOCOUNT ON;



- 在此处插入程序声明



SELECT EmployeeNumber

,CostCenter

,BusinessArea

,电话

,类别

,子类别



FROM [Portal]。[dbo]。[TaskRequest]

WHERE ID =(SELECT MAX(ID)FROM [Portal]。[dbo]。[TaskRequest]

WHERE EmployeeNumber = @EmployeeNumber)

结束



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。文件大小消息

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(确保总文件大小在{0:0。#} MB。,maxFileSize);

#endregion Max。文件大小的消息



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





if(SessionId == 1005)

{

SessionId =登录();

}


$ b



int statusId = ws.ServerStatus(SessionId);

string errorMessage = string.Empty;

switch(statusId)

{

case 1:

lblError .Visible = true;

btnSubmit.Enabled = false;

lblError.Text =检索会话时发生错误
错误详情:
服务桌面服务器不可用。;

errorMessage =用户:+ Page.User.Identity.Name +\ n
+ lblError.Text;



FitWebDev.Library.Logging.Log.WriteToEvent(errorMessage,System.Diagnostics.EventLogEntryType.Error,eventLogSource,Application);

Session.Remove(sid);

休息;

案例0:

#region获取类别和员工详细信息



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



lblEmployeeNumber。 Text = employeeNumber;







// Pre_Populating成本中心,电话和商业区// 25 JAN 2013

尝试使用(portalCnn)
{b $ b $

portalCnn.Open();

using(SqlCommand command = new SqlCommand(sp_Getuserinfo,portalCnn))

{



SqlDataReader reader = command.ExecuteReader();

// SqlDataReader reader = GetUserDetails(lblEmployeeNo);



while(读者) .Read())

{



lblEmployeeNumber.Text =(String)reader [EmployeeNumber];

lblCC.Text =(String)reader [CostCenter];

txtTelephone.Text =(String)reader [Telephone];

ddlBusinessArea.Text = (字符串)读取器[ BusinessArea];

ddlCategory.Text =(String)reader [Category];

ddlSubCategory.Text =(String)reader [SubCategory];



}

}

}

功能 / / Pre_Populating成本中心,电话和业务领域:日期:29/01

私有SqlDataReader PopulateUserDetails(字符串EmployeeNo)

{



使用(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 。打开();

返回cmd.ExecuteReader();





}

}





请帮助我不知道当我测试商店程序在数据库上工作时我做错了什么: - (

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 :-(

推荐答案

public SqlDataReader PopulateUserDetails(string EmployeeNo)
        {
            SqlDataReader reader = null;
            try
            {
                //get the connection string value from configuration file
                string strConnString = ConfigurationManager.ConnectionStrings["<connectionstringname>"].ConnectionString;
                using(SqlConnection con = new SqlConnection())
                {
                    SqlCommand cmd = new SqlCommand();
                    con.ConnectionString = strConnString;
                    cmd.Connection = con;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "dbo.sp_Getuserinfo";
                    SqlParameter param = new SqlParameter("@EmployeeNumber", EmployeeNo);
                    cmd.Parameters.Add(param);
                    reader = cmd.ExecuteReader();
                }

            }
            catch (Exception ex)
            {
                if (handleErrors)
                {
                    //Log the error
                    LogManager.Writer(ex.Message,LogType.Error);
                }
                else
                    throw;
            }

            return reader;
        }





你不必要多次添加SqlParameter

以下是你的一部分代码



you are unnecessarily adding the SqlParameter more than once
following is your part of code

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);





在你的存储过程中,你没有声明任何输出参数..你在C#代码中声明了一个输出参数。

这就是原因,它抛出期望参数''@EmployeeNumber'',未提供。



如果您需要更多帮助,请参阅以上代码参考。



如果您无法解决问题,请告诉我们..

快乐编码.. :)



with in your stored procedure, you are not declared any output parameter.. and you declared one output parameter in C# code.
that is the reason, it is throwing "expects parameter ''@EmployeeNumber'', which was not supplied."

If you want more help see the above code for ref.

Let us know, still if you are not able to resolve the prob..
Happy coding.. :)


这篇关于预填充页面加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 20:11