繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> 数据库应用 >> 如何使用数据查询的Parameters中的output属性取的返回值

如何使用数据查询的Parameters中的output属性取的返回值

2004-10-01 08:26:10  作者:  来源:互联网  浏览次数:19  文字大小:【】【】【
简介:public int AddMessage(int moduleId, int fatherId, String userName, String title, String body, String face) {             if (userName.L...

public int AddMessage(int moduleId, int fatherId, String userName, String title, String body, String face) {

if (userName.Length < 1) {

userName = "unknown";

}

// Create Instance of Connection and Command Object

SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);

SqlCommand myCommand = new SqlCommand("up_PostTopic", myConnection);

// Mark the Command as a SPROC

myCommand.CommandType = CommandType.StoredProcedure;

// Add Parameters to SPROC

SqlParameter parameterItemID = new SqlParameter("@ItemID", SqlDbType.Int, 4);

parameterItemID.Direction = ParameterDirection.Output;

myCommand.Parameters.Add(parameterItemID);

SqlParameter parameterFatherId = new SqlParameter("@FatherID", SqlDbType.Int, 4);

parameterFatherId.Value = fatherId;

myCommand.Parameters.Add(parameterFatherId);

SqlParameter parameterModuleID = new SqlParameter("@ModuleID", SqlDbType.Int, 4);

parameterModuleID.Value = moduleId;

myCommand.Parameters.Add(parameterModuleID);

SqlParameter parameterUserName = new SqlParameter("@CreatedByUser", SqlDbType.NVarChar, 100);

parameterUserName.Value = userName;

myCommand.Parameters.Add(parameterUserName);

SqlParameter parameterTitle = new SqlParameter("@Title", SqlDbType.NVarChar, 100);

parameterTitle.Value = title;

myCommand.Parameters.Add(parameterTitle);

SqlParameter parameterBody = new SqlParameter("@Content", SqlDbType.NVarChar, 4000);

parameterBody.Value = body;

myCommand.Parameters.Add(parameterBody);

SqlParameter parameterFace = new SqlParameter("@Face", SqlDbType.NVarChar, 100);

parameterFace.Value = face;

myCommand.Parameters.Add(parameterFace);

myConnection.Open();

myCommand.ExecuteNonQuery();

myConnection.Close();

return (int) parameterItemID.Value;

}

责任编辑:admin
相关文章