带参数添加

#region 带参数添加
                    //首先定义参数类型
                    SqlDbType[] lx = new SqlDbType[11];//表中要添加的需要添写数据的字段有9个
                    lx[0] = SqlDbType.NVarChar;
                    lx[1] = SqlDbType.NVarChar;
                    lx[2] = SqlDbType.NVarChar;
                    lx[3] = SqlDbType.NVarChar;
                    lx[4] = SqlDbType.NVarChar;
                    lx[5] = SqlDbType.NVarChar;
                    lx[6] = SqlDbType.NVarChar;
                    lx[7] = SqlDbType.NVarChar;
                    lx[8] = SqlDbType.NVarChar;
                    lx[9] = SqlDbType.NVarChar;
                    lx[10] = SqlDbType.NVarChar;
                    //其次二维数组,即参数名与参数值
                    string[,] strs = new string[11, 2];
                    strs[0, 0] = "@N_Lanmu"; strs[0, 1] = ClassID.ToString();
                    strs[1, 0] = "@N_title"; strs[1, 1] = txtTitle.Text.Trim();
                    strs[2, 0] = "@N_Publisher"; strs[2, 1] = txtfbr.Text.Trim();
                    strs[3, 0] = "@N_Department"; strs[3, 1] = txtbm.Text.Trim();
                    strs[4, 0] = "@N_Content"; strs[4, 1] = ASPxHtmlEditor1.Html;
                    strs[5, 0] = "@N_CreateDate"; strs[5, 1] = fubutime.Text.Trim();
                    strs[6, 0] = "@N_Click"; strs[6, 1] = Flag.ToString();
                    strs[7, 0] = "@N_Top"; strs[7, 1] = ZD.ToString();
                    strs[8, 0] = "@N_PX"; strs[8, 1] = TextBox2.Text.Trim();//排序
                    strs[9, 0] = "@Img_url"; strs[9, 1] = picurl.Text.Trim();
                    strs[10, 0] = "@Img_visible"; strs[10, 1] = xstp.ToString();
                    //定义INSERT语句
                    string strInsert = "insert into  NewsT values(@N_Lanmu,@N_title,@N_Publisher,@N_Department,@N_Content,@N_CreateDate,@N_Click,@N_Top,@N_PX,@Img_url,@Img_visible)";
                    //执行语句
                    if (db.ExecuteSql(strInsert, strs, lx))
                    {
                        Response.Write("<script>alert('添加成功!');location.href='AllNews.aspx'</script>");//转页2种方法
                    }
                    els
                    {
                        Response.Write("<script>alert('添加失败!');</script>");
                    }


                    #endregion
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值