/// <summary>
/// 插入数据
/// </summary>
/// <param name="ds">集合</param>
/// <returns>int</returns>
public int InsertUser( DataSet ds)
{
string sql = "Proc_DepotSales_InsertUser";
int ret = dbh.InsertDataSet(sql, CommandType.StoredProcedure, ds);
return ret;
}
//按钮事件
protected void btnRegister_Click(object sender, EventArgs e)
{
DataSet dsuser = new DataSet();
//创建用户表
DataTable dtuser = new DataTable("user");
//创建用户姓名列
DataColumn dcuserName = new DataColumn("UserLoginName", typeof(string));
dcuserName.MaxLength = 50;
//创建用户密码列
DataColumn dcpwd = new DataColumn("UserLoginPass", typeof(string));
dcpwd.MaxLength = 50;
//创建人员Id
DataColumn dcpid = new DataColumn("PersonID", typeof(int));
//将定义好的列添加到用户表中
dtuser.Columns.Add(dcuserName);
dtuser.Columns.Add(dcpwd);
dtuser.Columns.Add(dcpid);
//创建一个新的数据行
DataRow drUser = dtuser.NewRow();
drUser["userLoginName"] = this.txtUserName.Text.Trim();
drUser["userLoginPass"] = this.txtPwd.Text.Trim();
drUser["personID"] = this.txtPersonId.Text.Trim();
//将新的数据行插入用户表中
dtuser.Rows.Add(drUser);
//将用户表太能加到DataSet中
dsuser.Tables.Add(dtuser);
if (result > 0)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('注册成功!');</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('注册失败!');</script>");
}
}
存储过程
USE DepotSales
GO
IF EXISTS(SELECt * FROM sysobjects WHERe [NAME]='Proc_DepotSales_InsertUser')
DROP PROC Proc_DepotSales_InsertUser
GO
CREATE PROC Proc_DepotSales_InsertUser
@UserLoginName nvarchar(20),
@UserLoginPass nvarchar(20),
@PersonID int,
@Remark nvarchar(max)
AS
BEGIN TRANSACTION
DECLARE @i INT
SET @i=0
INSERT INTO [DepotSales].[dbo].[DepotSales_User]
([UserLoginName]
,[UserLoginPass]
,[PersonID]
)
VALUES
(@UserLoginName,
@UserLoginPass,
@PersonID
)
SET @i=@i+@@error
if @i<>0
BEGIN
Print '添加失败'
ROLLBACK TRANSACTION
END
else
BEGIN
Print '添加成功'
COMMIT TRANSACTION
END
报错截图:
过程或函数 'Proc_DepotSales_InsertUser' 需要参数 '@UserLoginName',但未提供该参数。说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Exception: 过程或函数 'Proc_DepotSales_InsertUser' 需要参数 '@UserLoginName',但未提供该参数。
希望帮我分析该问题并予以解答,如本人满意高分答谢!