use master
go
if exists(select name from sys.databases where name='Test_')
drop database Test_
go
create database Test_
go
use Test_
go
if exists(select name from sys.objects where name='Table_')
drop table Table_
go
create table Table_
(
ID int identity(100,1),
Tname varchar(50)
)
go
if exists(select name from sys.objects where name='Table_Proc')
drop procedure Table_Proc
go
create procedure Table_Proc
@Tname varchar(50),
@Show varchar(100) output
as
insert into Table_(Tname) values(@Tname)
set @Show='编号为:'+cast(@@identity as varchar(100))
go
declare @str varchar(100)
execute Table_Proc '哈哈', @str output
print @str
go
select * from Table_
go
protected void Page_Load(object sender, EventArgs e)
{
}
SqlConnection Connection;
private void SQLConnection()
{
string str = "server=.;uid=sa;pwd=sa;database=Test_";
Connection = new SqlConnection(str);
if (Connection.State == ConnectionState.Closed)
{
Connection.Open();
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
SQLConnection();
SqlParameter[] Parms =
{
new SqlParameter("@Tname",SqlDbType.VarChar,50),
new SqlParameter("@Show",SqlDbType.VarChar,100)
};
Parms[0].Value = txtName.Text;
Parms[1].Direction = ParameterDirection.Output;
SqlCommand Command = new SqlCommand("Table_Proc",Connection);
Command.CommandType = CommandType.StoredProcedure;
Command.Parameters.AddRange(Parms);
Command.ExecuteNonQuery();
//Response.Write(Parms[1].Value.ToString());
Show(Parms[1].Value.ToString());
}
protected void Show(string strShow)
{
string strScript= "<script>alert('" +strShow+ "')</script>";
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "",strScript);
}