先建立过程:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

ALTER proc insert_my_value
@myname char(10),
@mypassword char(10),
@myoutput int output
as
insert into mydatabase1(name,password) values(@myname,@mypassword)
select @myoutput = count(*) from mydatabase1

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

连接代码:
sqlConnection1=new System.Data.SqlClient.SqlConnection(@"workstation id=OB19;packet size=4096;integrated security=SSPI;data source=OB19;persist security info=False;initial catalog=myTest");
sqlConnection1.Open();
sqlCommand1=new System.Data.SqlClient.SqlCommand("insert_my_value");
sqlCommand1.Connection=sqlConnection1;
sqlCommand1.CommandType=CommandType.StoredProcedure;
sqlCommand1.Parameters.Add("@myname",SqlDbType.VarChar);
sqlCommand1.Parameters["@myname"].Value="macroideal";
sqlCommand1.Parameters.Add("@mypassword",SqlDbType.VarChar);
sqlCommand1.Parameters["@mypassword"].Value="macroideal";
sqlCommand1.Parameters.Add("@myoutput",SqlDbType.Int,16);
sqlCommand1.Parameters["@myoutput"].Direction=ParameterDirection.Output;
sqlCommand1.ExecuteScalar();
MessageBox.Show(sqlCommand1.Parameters["@myoutput"].Value.ToString());
































