本文介绍了得到错误“过程或函数”sp_insert_update_tblEmployee'期望参数'@intID',这是未提供的。“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在asp.net中创建3 tiar应用程序
我的ValueObjectLayer低于
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
命名空间 ValueObjectLayer
{
public class clsEmployeeVO
{
public int intID {获取; set ; }
public string strName { get 跨度>; set ; }
public string strMobile { get 跨度>; set ; }
public string strEmail { get 跨度>; set ; }
public DateTime dtBirthDate { get ; set ; }
// public Boolean blStatus {get;组; }
public string strCreatedBy {获得跨度>; set ; }
public DateTime dtCreatedDate { get ; set ; }
public string strUpdatedBy { get 跨度>; set ; }
public DateTime dtUpdatedDate { get ; set ; }
}
}
和我的DataAccessLayer是
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Data;
使用 System.Configuration;
使用 System.Data.SqlClient;
使用 ValueObjectLayer;
命名空间 DataAccessLayer
{
public class clsEmployeeDAL
{
SqlCommand objCmd;
int intCount;
SqlDataReader sqlrd;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [ STRCON跨度>]的ConnectionString)。
public int RegisterEmployeeDAL(clsEmployeeVO objEmployee)
{
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
objCmd = new SqlCommand();
objCmd.CommandText = sp_insert_update_tblEmployee;
objCmd.Connection = con;
objCmd.Parameters.Clear();
objCmd.Parameters.AddWithValue( @ intID,objEmployee.intID);
objCmd.Parameters.AddWithValue( @ strName,objEmployee.strName);
objCmd.Parameters.AddWithValue( @ strMobile,objEmployee.strMobile);
objCmd.Parameters.AddWithValue( @ strEmail,objEmployee.strEmail);
objCmd.Parameters.AddWithValue( @ dtBirthDate,objEmployee.dtBirthDate);
// objCmd.Parameters.AddWithValue(@ blStatus,objEmployee.blStatus);
objCmd.Parameters.AddWithValue( @ strCreatedBy,objEmployee.strCreatedBy);
objCmd.Parameters.AddWithValue( @ strUpdatedBy,objEmployee.strUpdatedBy);
intCount = Convert.ToInt32(objCmd.ExecuteNonQuery());
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
catch (例外情况)
{
return intCount = 0 ;
}
return intCount;
}
}
}
和我的BussinessAccessLayer是
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 DataAccessLayer;
使用 ValueObjectLayer;
命名空间 BussinessAccessLayer
{
public class clsEmployeeBAL
{
public int RegisterEmployeeDAL (clsEmployeeVO objEmployee)
{
clsEmployeeDAL objDAL = new clsEmployeeDAL();
return objDAL.RegisterEmployeeDAL(objEmployee);
}
}
}
和我的商店购买者是
USE [dbDemo]
GO
/ * *****对象:StoredProcedure [dbo]。[sp_insert_update_tblEmployee]脚本日期:09-01-2016 10:35:57 **** ** /
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo]。[sp_insert_update_tblEmployee]
@ intID int ,
@ strName nvarchar ( 50 ),
@ strMobile nvarchar ( 50 ),
@ strEmail nvarchar ( 50 ),
@dtBirthDate nvarchar ( 50 ),
- @ dtCreatedDate datetime,
- @ dtUpdatedDate datetime,
@ strCreatedBy nvarchar ( 50 ),
@ strUpdatedBy nvarchar ( 50 ),
@ intCount int 输出
AS
BEGIN TRANSACTION COMPILE_ALL
BEGIN 尝试
如果(不 存在(选择 intID 来自 tblEmployee 其中 intID = @ intID))
开始
插入 into tblEmployee(strName,strMobile,strEmail,dtBirthDate,strCreatedBy,dtCreatedDate,strUpdatedBy,dtUpdatedDate) values
( @ strName , @ strMobile , @ strEmail , @ dtBirthDate , @ strCreatedBy ,GETDATE(), @ strUpdatedBy , GETDATE())
end
else
开始
update tblEmployee set strName = @ strName ,strMobile = @ strMobile,strEmail = @ strEmail,dtBirthDate = @ dtBirthDate,
strUpdatedBy = @ strUpdatedBy,dtUpdatedDate = GETDATE()其中 intID = @ intID
end
COMMIT TRANSACTION COMPILE_ALL
set @ intCount = 1
END 尝试
BEGIN CATCH
ROLLB确认 TRANSACTION COMPILE_ALL
设置 @intCount = 0
END CATCH
和我的保存按钮代码是
protected void Button1_Click( object sender,EventArgs e)
{
clsEmployeeBAL objBAL = new clsEmployeeBAL();
clsEmployeeVO objVO = new clsEmployeeVO();
objVO.intID = 0 ;
objVO.strName = txtName.Text;
objVO.strMobile = txtMobile.Text;
objVO.strEmail = txtEmail.Text;
objVO.dtBirthDate = Convert.ToDateTime(txtBirthDate.Text);
objVO.strCreatedBy = Admin;
objVO.strUpdatedBy = ;
objBAL.RegisterEmployeeDAL(objVO);
ClearAll();
}
i收到错误程序或函数'sp_insert_update_tblEmployee'需要参数'@intID',这是未提供的。
解决方案
i am create 3 tiar application in asp.net
my ValueObjectLayer is below
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ValueObjectLayer { public class clsEmployeeVO { public int intID { get; set; } public string strName { get; set; } public string strMobile { get; set; } public string strEmail { get; set; } public DateTime dtBirthDate { get; set; } //public Boolean blStatus { get; set; } public string strCreatedBy { get; set; } public DateTime dtCreatedDate { get; set; } public string strUpdatedBy { get; set; } public DateTime dtUpdatedDate { get; set; } } }
and my DataAccessLayer is
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Configuration; using System.Data.SqlClient; using ValueObjectLayer; namespace DataAccessLayer { public class clsEmployeeDAL { SqlCommand objCmd; int intCount; SqlDataReader sqlrd; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["strCon"].ConnectionString); public int RegisterEmployeeDAL(clsEmployeeVO objEmployee) { try { if (con.State == ConnectionState.Closed) { con.Open(); } objCmd = new SqlCommand(); objCmd.CommandText = "sp_insert_update_tblEmployee"; objCmd.Connection = con; objCmd.Parameters.Clear(); objCmd.Parameters.AddWithValue("@intID", objEmployee.intID); objCmd.Parameters.AddWithValue("@strName", objEmployee.strName); objCmd.Parameters.AddWithValue("@strMobile", objEmployee.strMobile); objCmd.Parameters.AddWithValue("@strEmail", objEmployee.strEmail); objCmd.Parameters.AddWithValue("@dtBirthDate", objEmployee.dtBirthDate); //objCmd.Parameters.AddWithValue("@blStatus", objEmployee.blStatus); objCmd.Parameters.AddWithValue("@strCreatedBy", objEmployee.strCreatedBy); objCmd.Parameters.AddWithValue("@strUpdatedBy", objEmployee.strUpdatedBy); intCount = Convert.ToInt32(objCmd.ExecuteNonQuery()); if (con.State == ConnectionState.Open) { con.Close(); } } catch (Exception ex) { return intCount = 0; } return intCount; } } }
and my BussinessAccessLayer is
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DataAccessLayer; using ValueObjectLayer; namespace BussinessAccessLayer { public class clsEmployeeBAL { public int RegisterEmployeeDAL(clsEmployeeVO objEmployee) { clsEmployeeDAL objDAL = new clsEmployeeDAL(); return objDAL.RegisterEmployeeDAL(objEmployee); } } }
and my store procuder is
USE [dbDemo] GO /****** Object: StoredProcedure [dbo].[sp_insert_update_tblEmployee] Script Date: 09-01-2016 10:35:57 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[sp_insert_update_tblEmployee] @intID int, @strName nvarchar(50), @strMobile nvarchar(50), @strEmail nvarchar(50), @dtBirthDate nvarchar(50), --@dtCreatedDate datetime, --@dtUpdatedDate datetime, @strCreatedBy nvarchar(50), @strUpdatedBy nvarchar(50), @intCount int output AS BEGIN TRANSACTION COMPILE_ALL BEGIN try if(not exists (select intID from tblEmployee where intID=@intID)) begin insert into tblEmployee (strName,strMobile,strEmail,dtBirthDate,strCreatedBy,dtCreatedDate,strUpdatedBy,dtUpdatedDate)values (@strName,@strMobile,@strEmail,@dtBirthDate,@strCreatedBy,GETDATE(),@strUpdatedBy,GETDATE()) end else begin update tblEmployee set strName=@strName,strMobile=@strMobile,strEmail=@strEmail,dtBirthDate=@dtBirthDate, strUpdatedBy=@strUpdatedBy,dtUpdatedDate=GETDATE() where intID=@intID end COMMIT TRANSACTION COMPILE_ALL set @intCount = 1 END try BEGIN CATCH ROLLBACK TRANSACTION COMPILE_ALL set @intCount = 0 END CATCH
and my save button code is
protected void Button1_Click(object sender, EventArgs e) { clsEmployeeBAL objBAL = new clsEmployeeBAL(); clsEmployeeVO objVO = new clsEmployeeVO(); objVO.intID = 0; objVO.strName = txtName.Text; objVO.strMobile = txtMobile.Text; objVO.strEmail = txtEmail.Text; objVO.dtBirthDate = Convert.ToDateTime(txtBirthDate.Text); objVO.strCreatedBy = "Admin"; objVO.strUpdatedBy = ""; objBAL.RegisterEmployeeDAL(objVO); ClearAll(); }
i got an error "Procedure or function 'sp_insert_update_tblEmployee' expects parameter '@intID', which was not supplied."
解决方案
这篇关于得到错误“过程或函数”sp_insert_update_tblEmployee'期望参数'@intID',这是未提供的。“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!