像这样改变你的程序
create procedure [dbo].[TestRecordSelectMInfo3]
@GRNo varchar(4),
@SName varchar(35) output,
@Class Varchar(15) output
as
begin
Select @SName = Students.SName, @Class = Class.Class from Students inner join Class on Students.ClassId = Class.ClassId where Students.GRNo = @GRNo
end
用法:
private void GetData()
{
cmd.Parameters.Clear();
cmd.Parameters.Add("@GRNo", SqlDbType.VarChar).Value = tbgrno.Text;
SqlParameter SName = new SqlParameter("@SName", SqlDbType.VarChar);
SqlParameter Class = new SqlParameter("@Class", SqlDbType.VarChar);
SName.Direction = ParameterDirection.Output;
Class.Direction = ParameterDirection.Output;
SName.Size = 35;
Class.Size = 15;
cmd.Parameters.Add(SName);
cmd.Parameters.Add(Class);
dm.ExectNonActQuery("TestRecordSelectMInfo", cmd);
tbsname.Text = cmd.Parameters["@SName"].Value.ToString();
tbclass.Text = cmd.Parameters["@Class"].Value.ToString();
}
public void ExectNonActQuery(string spname, SqlCommand command)
{
SqlConnection cn = new SqlConnection("connection string");
cmd = command;
cmd.Connection = cn;
cmd.CommandText = spname;
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
}