如何通过.NET调用存储过程将数据高效添加至数据库中?
- 内容介绍
- 文章标签
- 相关推荐
本文共计178个文字,预计阅读时间需要1分钟。
调用存储过程比使用SQL语句操作速度快;代码如下:csharpprotected 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();
}
}
部分截图:
本文共计178个文字,预计阅读时间需要1分钟。
调用存储过程比使用SQL语句操作速度快;代码如下:csharpprotected 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();
}
}

