是我第一次来ASP.Net所以...
我创建了一个存储过程,现在我想将这个存储过程放在一个GridView中并进行连接,我的问题是由于StatementType的原因,我不知道如何为我的存储过程进行连接。当我执行选择、更新、选择或删除我的StatementType时,转到正确的操作。我的问题是,我必须在文本框中的哪里进行连接,Gridview...?
我的存储过程:
CREATE PROCEDURE SP_Employees
(@EmployeeID INT,
@EmployeeName VARCHAR(255),
@EmployeeUsername VARCHAR(255),
@EmployeeEmail VARCHAR(255),
@GroupID INT,
@Password VARCHAR(255),
@StatementType NVARCHAR(20) = ''
)
AS
BEGIN
IF @StatementType = 'INSERT'
BEGIN
INSERT INTO [Employees]([EmployeeID], [EmployeeName], [EmployeeUsername], [EmployeeEmail], [GroupID], [Password])
VALUES (@EmployeeID, @EmployeeName, @EmployeeUsername, @EmployeeEmail, @GroupID, @Password);
END
ELSE IF @StatementType = 'SELECT'
BEGIN
SELECT *
FROM [Employees];
END
ELSE IF @StatementType = 'Update'
BEGIN
UPDATE [Employees]
SET [EmployeeName] = @EmployeeName,
[EmployeeUsername] = @EmployeeUsername,
[EmployeeEmail] = @EmployeeEmail,
[GroupID] = @GroupID,
[Password] = @Password
WHERE
[EmployeeID] = @EmployeeID;
END
ELSE IF @StatementType = 'DELETE'
BEGIN
DELETE FROM [Employees]
WHERE [EmployeeID] = @EmployeeID;
END;
END
发布于 2018-05-29 07:31:02
GridView易用性的全部思想是,您根本不需要存储过程。
如果您的数据库管理员只允许您使用存储过程进行访问,那么您可以指定一个自定义的SelectMethod、UpdateMethod和DeleteMethod,然后手动映射从GridView获得的值来调用您的存储过程,但是要完成GridView可以为您轻松完成的工作,这是一个非常漫长的过程。
// The id parameter name should match the DataKeyNames value set on the control
public void EmployeeTable_UpdateItem(int id)
{
InvMS.Models.Employee item = null;
// Load the item here, e.g. item = MyDataLayer.Find(id);
if (item == null)
{
// The item wasn't found
ModelState.AddModelError("", String.Format("Item with id {0} was not found", id));
return;
}
TryUpdateModel(item);
if (ModelState.IsValid)
{
// Create a connection to your database here,
// Map the attributes to your stored procedure and call the procedure
}
}
// The id parameter name should match the DataKeyNames value set on the control
public void EmployeeTable_DeleteItem(int id)
{
}
https://stackoverflow.com/questions/50569645
复制相似问题