请教关于ado.net调用存储过程
我在sqlserver中写了一个存储过程
希望进行调用并返回一个结果(int类型)
谢谢
------解决方案----------------------SQL
create proc sp_AuthorStateOutPut
@state varchar(2),
@count int output
as
select * from authors where state = @state
set @count = @@rowcount
select * from authors
return @@rowcount
go
//有输出参数和返回值的Demo
SqlConnection cn = new SqlConnection( "server=.;uid=sa;pwd=sa;database=pubs ");
SqlCommand cmd = new SqlCommand( "sp_AuthorStateOutput ", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add( "@returnvalue ",SqlDbType.Int);
cmd.Parameters[ "@returnvalue "].Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add( "@state ", SqlDbType.VarChar).Value = DropDownList1.SelectedValue;
cmd.Parameters.Add( "@count ",SqlDbType.Int);
cmd.Parameters[ "@count "].Direction = ParameterDirection.Output;
cn.Open();
DataGrid1.DataSource = cmd.ExecuteReader();
DataGrid1.DataBind();
cn.Close();
Label1.Text = cmd.Parameters[ "@count "].Value.ToString() + "/ " + cmd.Parameters[ "@returnvalue "].Value.ToString();