ADO绑定SQL数据库过程
--1 更新特定表中记录的存储过程并在WEBpage中使用ADO调用。
use MySchool
select * from Class
insert into Class values('net','优秀班级体')
create proc usp_T_Class_update
@classId int,
@cName varchar(50),
@cDescription varchar(50)
as
begin
update Class set cName=@cName, cDescription=@cDescription where clsId=@classId
end
exec usp_T_Class_update 7,'NET','超级班'
--ASP中前台代码
<form id="form1" runat="server">
<div>
请输入班号:<asp:TextBox ID="txtClassId" Text="" runat="server"></asp:TextBox><br />
请输入班级:<asp:TextBox ID="txtClass" Text="" runat="server"></asp:TextBox><br />
请输入荣誉:<asp:TextBox ID="txtRongYu" Text="" runat="server"></asp:TextBox><br />
<asp:Button ID="btn_update" runat="server" Text="更新"
onclick="btn_update_Click" />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
</form>
--ASP中后台代码
protected void btn_update_Click(object sender, EventArgs e)
{
int classId=Convert.ToInt32(txtClassId.Text);
string cname=txtClass.Text;
string cDescription=txtRongYu.Text;
string connStr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
using(SqlConnection conn=new SqlConnection(connStr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
string usp_name = "usp_T_Class_update";
cmd.CommandText = usp_name;
SqlParameter prm1=new SqlParameter("@classId",classId);
SqlParameter prm2=new SqlParameter("@cName",cname);
SqlParameter prm3=new SqlParameter("@cDescription",cDescription);
cmd.Parameters.Add(prm1);
cmd.Parameters.Add(prm2);
cmd.Parameters.Add(prm3);
int i= cmd.ExecuteNonQuery();
if (i > 0)
{
Label1.Text = "更新成功";