得到错误“过程或函数”sp_insert_update_tblEmployee'期望参数'@intID',这是未提供的。“ [英] got an error "Procedure or function 'sp_insert_update_tblEmployee' expects parameter '@intID', which was not supplied."

查看:83
本文介绍了得到错误“过程或函数”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',这是未提供的。

解决方案

您还没有将命令类型设置为存储过程,请执行以下操作

 objCmd =  new  SqlCommand(); 
objCmd.CommandText = sp_insert_update_tblEmployee;
objCmd.CommandType = CommandType.StoredProcedure;


正如DamithSL指出的那样,你应该定义命令类型。此外,您似乎缺少一个参数, @intCount 未定义,因此您的代码应包含类似

的内容objCmd.Parameters.Add(  @ intCount,SqlDbType.Int).Direction = ParameterDirection.Output; 


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."

解决方案

you haven't set command type as stored procedure, do as below

objCmd = new SqlCommand();
objCmd.CommandText = "sp_insert_update_tblEmployee";
objCmd.CommandType = CommandType.StoredProcedure;


As DamithSL pointed out you should define the command type. Also you seem to be missing one parameter, @intCount is not defined so your code should include something like

objCmd.Parameters.Add("@intCount", SqlDbType.Int).Direction = ParameterDirection.Output;


这篇关于得到错误“过程或函数”sp_insert_update_tblEmployee'期望参数'@intID',这是未提供的。“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆