首页 新闻 搜索 专区 学院

SqlParameter赋值之后怎么添加值

0
悬赏园豆:20 [已解决问题] 解决于 2008-01-15 21:22
<P>SqlParameter赋值之后怎么添加值</P> <P>用SqlCommand我知道用add <BR>但我想问的是 &nbsp; SqlParameter <BR><BR>例如 <BR>SqlParameter &nbsp; parm &nbsp; = &nbsp; new &nbsp; SqlParameter(PARM_ORDER_ID, &nbsp; SqlDbType.Int); <BR>parm.Value &nbsp; = &nbsp; orderId; <BR><BR>之后能不能再改parm添加一个值 <BR>因为我写了个方法是传递SqlParameter类型的参数 <BR>但有时要做些判断 <BR>像 <BR>SqlParameter &nbsp; parm &nbsp; = &nbsp; new &nbsp; SqlParameter(PARM_ORDER_ID, &nbsp; SqlDbType.Int); <BR>parm.Value &nbsp; = &nbsp; orderId; <BR><BR>if(...) <BR>{ <BR>//添加一个参数 <BR>} <BR><BR>ExecuteReader(parm,.....); <BR><BR>请问应该怎么做呢</P>
cloudgamer的主页 cloudgamer | 菜鸟二级 | 园豆:280
提问于:2008-01-12 19:15
< >
分享
最佳答案
0
int IArticle.Insert(ArticleInfo article) { //如果对象存在 if (article.ID != -1) return -1; else article.ID = TableHelper.GetSequence(SQLHelper.ConnectionString, "Article", "ID"); //统计执行成功的数量 int successCount = 0; string SQL_THIS = SQL_INSERT_ARTICLE; SqlParameter[] paras = GetParas(); paras[0].Value = article.ID; paras[1].Value = article.Title; paras[2].Value = article.DateAdded; paras[3].Value = article.Text; paras[4].Value = article.SourceUrl; paras[5].Value = article.PostType; paras[6].Value = article.Author; paras[7].Value = article.Email; paras[8].Value = article.SourceName; paras[9].Value = article.BlogID; paras[10].Value = article.CategoryID; paras[11].Value = article.Summary; paras[12].Value = article.IsBySummary; paras[13].Value = article.DateUpdated; paras[14].Value = article.TitleUrl; paras[15].Value = article.FeedBackCount; paras[16].Value = article.PostConfig; paras[17].Value = article.EntryName; paras[18].Value = article.KeyWord; SqlConnection conn = new SqlConnection(SQLHelper.ConnectionString); successCount = SQLHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_THIS, paras); return successCount; }
volnet(可以叫我大V) | 小虾三级 |园豆:720 | 2008-01-13 21:20
其他回答(3)
0
SqlParameter parm = new SqlParameter(PARM_ORDER_ID, SqlDbType.Int); parm.Value = orderId; if(...) { //添加一个参数: parm.ParameterName="@AnotherName"; parm.DbType=....; parm.Value=...; } ExecuteReader(parm,.....);
deerchao | 园豆:8167 (大侠五级) | 2008-01-12 22:26
0
我一般都使用SqlParameter [],创建需要的最多参数,不需要的不赋值,效果是一样的,比较省事儿
丁学 | 园豆:18530 (专家六级) | 2008-01-13 10:00
0
用数组啦~~~
endision | 园豆:210 (菜鸟二级) | 2008-01-15 14:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册