0
点赞
收藏
分享

微信扫一扫

Net调用存储过程实现添加数据到数据库

 调用存储过程比用sql语句操作速度要快;

代码如下:

protected void Button1_Click(object sender, EventArgs e)

   {

       if (this.TextBox1.Text!="")

       {

         SqlConnection sc=  help.con();

           sc.Open();

          // string str = "insert into cs(Fcate) values('"+this.TextBox1.Text.Trim()+"')";

           SqlCommand cmd = new SqlCommand("cs_Insert", sc);

           cmd.CommandType = CommandType.StoredProcedure;

         //添加参数,给参数赋值

           cmd.Parameters.Add(new SqlParameter("@fcate", SqlDbType.VarChar,128)).Value=this.TextBox1.Text.Trim();

           cmd.ExecuteNonQuery();

           sc.Close();

          //从新绑定数据源

           this.Bind();

       }

   }

部分截图:

Net调用存储过程实现添加数据到数据库_存储过程

举报

相关推荐

0 条评论