ASP.NET过程或函数 'sp_setSys' 需要参数 '@param',但未提供该参数。
///<summary>///执行一个SQL语句或一个存储过程,并返回受影响的记录数///</summary>///<paramname="query">SQL语句或是存...
/// <summary>
/// 执行一个SQL语句或一个存储过程,并返回受影响的记录数
/// </summary>
/// <param name="query">SQL语句或是存储过程名</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(string query)
{
using (SqlConnection connection = ConnectionManager.GetConnectionObject())
{
connection.Open();
using (SqlCommand cmd = new SqlCommand(query, connection))
{
if (query.StartsWith("INSERT") | query.StartsWith("insert") | query.StartsWith("UPDATE") | query.StartsWith("update") | query.StartsWith("DELETE") | query.StartsWith("delete"))
{
cmd.CommandType = CommandType.Text;
}
else
{
cmd.CommandType = CommandType.StoredProcedure;
}
return cmd.ExecuteNonQuery();
}
}
}
存储过程
USE [db_TES]
GO
/****** Object: StoredProcedure [dbo].[sp_setSys] Script Date: 04/23/2018 13:26:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:Ben
-- Description:设置系统状态
-- =============================================
ALTER PROCEDURE [dbo].[sp_setSys]
@param nvarchar(8)
AS
BEGIN
IF (@param='关闭系统')
begin
update tb_stu set Lock='true';
update tb_worker set Lock='true';
end
ELSE
begin
update tb_stu set Lock='false';
update tb_worker set Lock='false';
end
END 展开
/// 执行一个SQL语句或一个存储过程,并返回受影响的记录数
/// </summary>
/// <param name="query">SQL语句或是存储过程名</param>
/// <returns>受影响的行数</returns>
public static int ExecuteNonQuery(string query)
{
using (SqlConnection connection = ConnectionManager.GetConnectionObject())
{
connection.Open();
using (SqlCommand cmd = new SqlCommand(query, connection))
{
if (query.StartsWith("INSERT") | query.StartsWith("insert") | query.StartsWith("UPDATE") | query.StartsWith("update") | query.StartsWith("DELETE") | query.StartsWith("delete"))
{
cmd.CommandType = CommandType.Text;
}
else
{
cmd.CommandType = CommandType.StoredProcedure;
}
return cmd.ExecuteNonQuery();
}
}
}
存储过程
USE [db_TES]
GO
/****** Object: StoredProcedure [dbo].[sp_setSys] Script Date: 04/23/2018 13:26:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:Ben
-- Description:设置系统状态
-- =============================================
ALTER PROCEDURE [dbo].[sp_setSys]
@param nvarchar(8)
AS
BEGIN
IF (@param='关闭系统')
begin
update tb_stu set Lock='true';
update tb_worker set Lock='true';
end
ELSE
begin
update tb_stu set Lock='false';
update tb_worker set Lock='false';
end
END 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询