当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  存储过程的分析

 存储过程的分析

点击次数:29 次 发布日期:2008-11-26 12:21:27 作者:源代码网
源代码网推荐      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 }
源代码网推荐  
源代码网推荐  http://www.cnblogs.com/chenhui3344/archive/2006/10/30/544787.html
源代码网推荐  
源代码网推荐  
源代码网推荐    做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华