日期:2014-05-18  浏览次数:20365 次

asp.net 执行带多个参数的存储过程
RT   单个参数的我会   但是多个找了下网上实例代码   貌似都太麻烦     在asp里面执行多个参数的存储过程倒是蛮简单的   难道到了。net里面反而复杂了?

------解决方案--------------------
SqlParameter[] parameters = {
new SqlParameter( "@fhaid ",SqlDbType.UniqueIdentifier),
new SqlParameter( "@archivesnum ",SqlDbType.NVarChar ,30),
new SqlParameter( "@holdername ", SqlDbType.NVarChar ,100),
new SqlParameter( "@personnum ", SqlDbType.Int ,4),
new SqlParameter( "@familytype ", SqlDbType.NVarChar ,50),
new SqlParameter( "@telephone ", SqlDbType.Char ,20),
new SqlParameter( "@town ", SqlDbType.NVarChar ,50),
new SqlParameter( "@village ", SqlDbType.NVarChar ,50),
new SqlParameter( "@country ", SqlDbType.NVarChar ,50),
new SqlParameter( "@creationdoctor ", SqlDbType.NVarChar ,50),
new SqlParameter( "@archivescreationdate ", SqlDbType.DateTime),
new SqlParameter( "@communityservice ", SqlDbType.NVarChar ,100),
new SqlParameter( "@creationdate ", SqlDbType.NChar ,10),
new SqlParameter( "@lastupdatedate ", SqlDbType.DateTime)
};
parameters[0].Value = model.FHAID;
parameters[1].Value = model.ArchivesNum;
parameters[2].Value = model.HolderName;
parameters[3].Value = model.PersonNum;
parameters[4].Value = model.FamilyType;
parameters[5].Value = model.Telephone;
parameters[6].Value = model.Towm;
parameters[7].Value = model.Village;
parameters[8].Value = model.Country;
parameters[9].Value = model.CreationDoctor;
parameters[10].Value = model.ArchivesCreationDate;
parameters[11].Value = model.CommunityService;
parameters[12].Value = model.CreationDate;
parameters[13].Value = model.LastUpdateDate;

------解决方案--------------------
很复杂么?

public DataSet GetTopics(int forumID, int pageNumber, int pageSize)
{
SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings[ "ConnectionString "]);
SqlDataAdapter da = new SqlDataAdapter( "sp_Forums_GetTopicsByPage ", cn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter[] parameters = {
new SqlParameter( "@ForumID ", SqlDbType.Int, 4),
new SqlParameter( "@PageNumber ", SqlDbType.Int, 4),
new SqlParameter( "@PageSize ", SqlDbType.Int, 4)
};
parameters[0].Value = forumID;
parameters[1].Value = pageNumber;
parameters[2].Value = pageSize;

foreach (SqlParameter parameter in parameters)
{
da.SelectCommand.Parameters.Add(parameter);
}

DataSet ds = new DataSet();
cn.Open();
da.Fill(ds);
cn.Close();

return ds;
}
------解决方案--------------------
public int TestPageInsert(TestPageInfo test)
{
string sql = "s_TestPage_Insert ";
SqlCommand sqlcmd = new SqlCommand(sql,DwzxConfiguration.ConnectDB() ,DwzxConfiguration.SqlTran);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.Add( "@Title ",SqlDbType.VarChar ,50).V