储存过程介绍及c#中的应用4

 带参数和返回值的储存过程调用

CREATE PROCEDURE [dbo].c  (@user varchar(100), @pwd varchar(100) ) AS declare  @flag int
select * from 会员信息 where 帐号=@user  and 密码=@pwd
if @@rowcount > 0
 set @flag=1
else
 set @flag=0
return @flag
GO


C#中使用:
string connString = "Server = (local); Database = ChemChina; uid = sa; pwd = sa";
   System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
   conn.Open();
   System.Data.SqlClient.SqlCommand objCmd=conn.CreateCommand();
   objCmd.CommandText="c";
   objCmd.CommandType=CommandType.StoredProcedure ;
   //-----准备stored procedure 的参数-------
   objCmd.Parameters.Add("@user",SqlDbType.VarChar);
   objCmd.Parameters["@user"].Value=1;
   objCmd.Parameters.Add("@pwd",SqlDbType.VarChar);
   objCmd.Parameters["@pwd"].Value=1;
   objCmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("ReturnValue", SqlDbType.Int,4, ParameterDirection.ReturnValue, false,0,0, string.Empty,DataRowVersion.Default, null));
   //-----执行存储过程---------------------- 
   objCmd.ExecuteNonQuery();
   TextBox1.Text=objCmd.Parameters["ReturnValue"].Value.ToString();
   conn.Close();

你可能感兴趣的:(String,server,C#,user,database,textbox)