|
|
|
[
来路:21kn.com 时间:2007-7-8 17:41:54
点击: ] |
|
|
|
|
|
1 // 对存储过程的分析:实例 2 // string G_name ,string G_password为传递给此存储过程的参数,string Loging表示方法名和类型 3 4 public string Login( string G_Name , string G_Passord) 5 { 6 7 SqlConnection Conn = new SqlConnection(ConfigurationSettings.AppeSettings[ " ConnectionString " ]); 8 // 此为连接语句 9 /**/ /* 10 ConfigurationSettings.AppeSettings["ConnectionString"] 11 表示从Configurantion加载了一条连接语句 12 Config里的语句为 13 <appSettings> 14 <add key="ConnectionString" value="server=Localhost;uid=sa;pwd=sa; dataBase= Global" /> 15 </appSettings> 16 <system.web> 17 注意此标是放在<system.web>的上面 18 */ 19 SqlCommand Comm = new SqlCommand( " Login " ,Conn); 20 // 新建一个SqlCommand的实例Comm并把它标记为储蓄过程名为Login。 21 22 Comm.CommandType = CommandType.StoredProcedure; 23 // 将Comm标记为储蓄过程 24 25 26 27 // 下面为存储过程添加参数 28 SqlParameter parameterG_name = new SqlParameter( " @G_name " ,SqlDbType.NVarChar, 20 ); 29 // 新建了一个SqlParameter的储蓄过程参数实例:实例名为pranmeterG_name 30 // 并定义了一个名为"@G_name"的参数名,定义类型SqlDbType为NvarChar 字节数为20; 31 32 parameterG_name.Value = G_Name; 33 // 为参数实例parameterG_name赋值 为这个值是从方法Login中传递进来的值 34 // 注意parameterG_name.Value=G_name 中的G_name和语句new SqlParameter("@G_name",SqlDbType.NVarChar,20); 35 // 中的@G_name是不同,@G_name是为一个SqlParameter的储蓄过程定义的一个参数名 36 37 Comm.Parameters.Add(prarameterG_name); 38 // 为Comm为添加参数paratemterG_name 39 40 41 42 43 SqlParameter parameterG_password = new SqlParameter( " @G_password " ,SqlDbType.NVarChar, 20 ); 44 parameterG_password.Value = G_password; 45 Comm.Parameters.Add(parameterG_password); 46 47 SqlParameter parameterG_Id = new SqlParameter( " @G_Id " ,SqlDbType.Int, 4 ); 48 parameterG_Id.Direction = ParameterDirection.Output; 49 // parameterG_Id.dDirection 获取或者设置一个值,该值指示指示参数是只可 50 // 只可以输入,只可以输出,双向 还是存储过程返回值参数 51 // ParameterDirection.Output;定义了此参数为输出参数 52 Comm.Parameters.Add(paramerG_Id); 53 54 // 打开连接并执行Command命令 55 Conn.Open(); 56 Comm.ExecuteNonQuery(); 57 Conn.Close(); 58 59 // 对获得parameterG_Id.Value的值进行处理 60 int G_id = ( int )(parameterG_Id.Value); 61 62 if (G_id == 0 ) 63 { 64 return null ; 65 // 返回空 66 } 67 else 68 { 69 G_id.ToString(); 70 // 将此信息转换为等效字符串的表现形势 71 } |
|
|
::::站长友情提示:多花一分钟学点什么都好::::
|
|
|
|
|
|
|
|
|
|
|
|
=
= 免责声明 = = |
|
①
欢迎转载我网所刊信息,请注明“来源:E天下网络”。
② 凡本网注明“来源:XXX(非E天下网络)”的作品,均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如因作品内容、版权和其它问题需要同本网联系的,请在30日内进行。
※联系方式:Airtofly@163.com |
|
|
|
|
|
|