调用存储过程比用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)
调用存储过程比用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();
}
}