我有一个更改表中字段的应用程序。这是一个简单的表单,用户可以在其中更改与组关联的公司。
。网
public static string EditGroup(vw_Group_Model editGroup)
{
string outcome = "";
if (editGroup.RowType == "ALF")
{
try
{
using (SqlConnection conn = AlfOnlineConnection())
{
conn.Open();
UserManager.Models.vw_Group_Model model = new vw_Group_Model();
using (var command = new SqlCommand("sp_UserManager_EditGroup", conn))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@CompanyId", SqlDbType.Int).SqlValue = editGroup.companyId;
command.Parameters.Add("@GroupId", SqlDbType.Int).SqlValue = editGroup.groupId;
//command.Parameters.Add("@CompanyName", SqlDbType.NVarChar).SqlValue = editGroup.selected_company;
//command.Parameters.Add("@GroupName", SqlDbType.NVarChar).SqlValue = editGroup.groupName;
command.Parameters.Add("@StartDate", SqlDbType.DateTime).SqlValue = editGroup.StartDate;
command.Parameters.Add("@EndDate", SqlDbType.DateTime).SqlValue = editGroup.EndDate;
switch (editGroup.IsActive)
{
case true:
command.Parameters.Add("@isactive", SqlDbType.TinyInt).SqlValue = 1;
break;
case false:
command.Parameters.Add("@isactive", SqlDbType.TinyInt).SqlValue = 0;
break;
}
int rowsEdited = command.ExecuteNonQuery();
if (rowsEdited == 1)
{
outcome = "Row successfully edited.";
}
}
}
}
catch (SqlException ex)
{
return ex.ToString();
}
}
T-SQL
USE [BradOnline]
GO
/****** Object: StoredProcedure [dbo].[sp_UserManager_EditGroup] Script Date: 01/17/2013 13:11:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[sp_UserManager_EditGroup]
@GroupId INT,
@CompanyId INT,
--@GroupName NVARCHAR(50),
--@CompanyName NVARCHAR(50),
@StartDate DATETIME,
@EndDate DATETIME,
@isactive TINYINT
AS
BEGIN
DECLARE @AccountManagerId uniqueidentifier
SET @AccountManagerId = '7A1DC75D-2628-4F8D-A376-9382A0762568'
--(SELECT G.AccountManagerId FROM dbo.aspnet_Custom_Groups AS G
-- WHERE Id = @GroupId)
--DECLARE @CompanyId BIGINT
--SET @CompanyId = (SELECT MAX(c.Id) FROM dbo.aspnet_Custom_Companies AS c
-- WHERE c.Name = @CompanyName)
UPDATE
[dbo].[aspnet_Custom_Groups]
SET
--[Name] = @GroupName,
[StartDate] = @StartDate,
[EndDate] = @EndDate,
[IsActive] = @isactive,
[AccountManagerId] = NULL,
[CompanyId] = @CompanyId
WHERE
[Id] = @GroupId
END
在 SQL 中,如果我对更新的值进行硬编码,它可以工作,但如果我传递其中的值,则不会。我一直在寻找它的年龄,但没有得到任何地方。当我检查断点时,我的应用程序中的参数包含值