
asp.net的存储过程怎么在aspx页面调用?
3个回答
2013-07-09
展开全部
上面有代码了给你步骤吧.
把命令类型设置成T-SQL
然后创建存储过程参数并给值
然后填充进参数集合中
最后执行,返回结果.
就这么简单
把命令类型设置成T-SQL
然后创建存储过程参数并给值
然后填充进参数集合中
最后执行,返回结果.
就这么简单
2013-07-09
展开全部
SqlConnection DbConnection = new SqlConnection(mConnectionString);SqlCommand command = new SqlCommand( "sp_AccountRole_Create", DbConnection );DbConnection.Open(connectString);// 废置SqlCommand的属性为存储过程command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@CategoryID", SqlDbType.Int, 4);command.Parameters.Add("@RoleName", SqlDbType.NVarChar, 10);command.Parameters.Add("@Description", SqlDbType.NVarChar, 50);command.Parameters.Add("@RoleID", SqlDbType.Int, 4);// 返回值command.Parameters.Add("Returnvalue", SqlDbType.Int, 4, // Size ParameterDirection.Returnvalue, false, // is nullable 0, // byte precision 0, // byte scale string.Empty, DataRowVersion.Default, null );
command.parameters["@CategoryID"].value = permission.CategoryID;command.parameters["@RoleName"].value = permission.PermissionName;command.parameters["@Description"].value = permission.Description;// 能够返回新的ID值command.parameters["@RoleID"].Direction = ParameterDirection.Output;
int rowsAffected = command.ExecuteNonQuery();int result = command.parameters["Returnvalue"].value;int newID = command.parameters["@RoleID"].value;
command.Parameters.Add("@CategoryID", SqlDbType.Int, 4);command.Parameters.Add("@RoleName", SqlDbType.NVarChar, 10);command.Parameters.Add("@Description", SqlDbType.NVarChar, 50);command.Parameters.Add("@RoleID", SqlDbType.Int, 4);// 返回值command.Parameters.Add("Returnvalue", SqlDbType.Int, 4, // Size ParameterDirection.Returnvalue, false, // is nullable 0, // byte precision 0, // byte scale string.Empty, DataRowVersion.Default, null );
command.parameters["@CategoryID"].value = permission.CategoryID;command.parameters["@RoleName"].value = permission.PermissionName;command.parameters["@Description"].value = permission.Description;// 能够返回新的ID值command.parameters["@RoleID"].Direction = ParameterDirection.Output;
int rowsAffected = command.ExecuteNonQuery();int result = command.parameters["Returnvalue"].value;int newID = command.parameters["@RoleID"].value;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-09
展开全部
写成函数直接调就是了吗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询