新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论高级C/C++编程、代码重构(Refactoring)、极限编程(XP)、泛型编程等话题
    [返回] 中文XML论坛 - 专业的XML技术讨论区计算机技术与应用『 C/C++编程思想 』 → 请教基于.net的sql server访问基础类库的开发的问题 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 2369 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 请教基于.net的sql server访问基础类库的开发的问题 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     ronnyma 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:0
      积分:55
      门派:XML.ORG.CN
      注册:2006/4/25

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给ronnyma发送一个短消息 把ronnyma加入好友 查看ronnyma的个人资料 搜索ronnyma在『 C/C++编程思想 』的所有贴子 引用回复这个贴子 回复这个贴子 查看ronnyma的博客楼主
    发贴心情 请教基于.net的sql server访问基础类库的开发的问题

    有一段基础类库方面的代码,
    帮帮忙看看,解释一下,我看不太懂!!
    using System;
    using System.Data;

    namespace EMCL_DataBase
    {
     /// <summary>
     /// Class_DataDase 的摘要说明。
     /// 该类提供用于访问MS SQL SERVER数据库的方法
     /// 该类提供如下的方法:
     ///
     ///1.string[] ReadConfig()
     ///该方法用于读取包含系统本地配置的XML文档,文档的名称为LocalConfig.xml。读取的结果
     ///保存在一个字符串数组中返回
     ///2.void WriteConfig(string[] localConfig)
     ///该方法将保存在字符串数组中的本地配置信息写入LocalConfig.xml文档中.
     ///3.LocalConfig.xml的格式为
     /*
       <?xml version="1.0" standalone="yes"?>
       <XmlDataSet>
       <XmlTable>
       <Col_DataBaseServer>数据库服务器名称</Col_DataBaseServer>
       <Col_Account>访问服务器帐号</Col_Account>
       <Col_Password>访问服务器的密码</Col_Password>
       <Col_DefaultDataBase>默认数据库的名称</Col_DefaultDataBase>
       <Col_UnitName>使用系统单位名称<Col_UnitName>
       <Col_SystemName>系统名称</Col_SystemName>
       </XmlTable>
       </XmlDataSet>
        */
     ///4.LocalConfig.xml文档必须在可执行文件的目录下
     ///</summary>
     public struct Struct_Param
     {
      public string ParamName;
      public System.Data.SqlDbType SQLType;
      public int Length;
      public string Value;
     }
     public class Class_DataBase
     {
      private string Str_Connection;//连接串变量
      private System.Data.SqlClient.SqlConnection Sql_Connection;//SQL连接变量
      private System.Data.SqlClient.SqlCommand Sql_Command;

      public int Int_Count;
      private static string[] Str_LocalConfig=new String[6];
      public Class_DataBase(string[] localConfig)
      {
       Str_LocalConfig=localConfig;
      }
      public bool ConnectionCheck()
      {
       Str_Connection="user id="+Str_LocalConfig[1].Trim ()+";password="+Str_LocalConfig[2].Trim() +
        ";datasource=\""+Str_LocalConfig[0].Trim()+"\";persist security info=False;inital catalog="+Str_LocalConfig[3].
           Trim();
       Sql_Connection=new System.Data.SqlClient.SqlConnection(Str_Connection);
       try
       {
        Sql_Connection.Open();//测试连接
        Sql_Connection.Close();

        return true;//设置测试结果
       }
       catch
       {
        return false;//设置测试结果
       }

      }
      public bool ConnectionCheck(string[] localConfig)
      {
       Str_Connection="user id="+localConfig[1].Trim ()+";password="+localConfig[2].Trim() +";datasource=\""+localConfig[0].Trim()+"\";persist security info=False;inital catalog="+localConfig[3].Trim();
       Sql_Connection=new System.Data.SqlClient.SqlConnection(Str_Connection);
       try
       {
        Sql_Connection.Open();//测试连接
        Sql_Connection.Close();
                    
        return true;//设置测试结果
       }
       catch
       {
        return false;//设置测试结果
       }
      }

      public int ExecsSQLCommand(string SQLCommand)
      {
       Str_Connection="user id="+Str_LocalConfig[1].Trim ()+";password="+Str_LocalConfig[2].Trim() +";datasource=\""+Str_LocalConfig[0].Trim()+"\";persist security info=False;inital catalog="+Str_LocalConfig[3].
           Trim();
       Sql_Connection=new System.Data.SqlClient.SqlConnection(Str_Connection);
       Sql_Connection.Open();
       Sql_Command=new System.Data.SqlClient.SqlCommand();
       Sql_Command.Connection=Sql_Connection;
       Sql_Command.CommandType=System.Data.CommandType.Text;
       Sql_Command.CommandText=SQLCommand;
       Int_Count=Sql_Command.ExecuteNonQuery();
       Sql_Connection.Close();
                
       return Int_Count;
      }
      public System.Data.SqlClient.SqlDataReader ExecSQL(string SQLCommand)
      {
       System.Data.SqlClient.SqlDataReader RR;

       Str_Connection="user id="+Str_LocalConfig[1].Trim ()+";password="+Str_LocalConfig[2].Trim() +
        ";datasource=\""+Str_LocalConfig[0].Trim()+"\";persist security info=False;inital catalog="+Str_LocalConfig[3].
           Trim();
       Sql_Connection=new System.Data.SqlClient.SqlConnection(Str_Connection);
       Sql_Connection.Open();
       Sql_Command=new System.Data.SqlClient.SqlCommand();
       Sql_Command.Connection=Sql_Connection;
       Sql_Command.CommandType=System.Data.CommandType.Text;
       Sql_Command.CommandText=SQLCommand;
       RR=Sql_Command.ExecuteReader();
       Sql_Command.Dispose();
       return RR;
      }
            
      public System.Data.SqlClient.SqlDataReader ExecSQLProcess(string ProcName,Struct_Param[] Parm)
      {
       Str_Connection="user id="+Str_LocalConfig[1].Trim ()+";password="+Str_LocalConfig[2].Trim() +
        ";datasource=\""+Str_LocalConfig[0].Trim()+"\";persist security info=False;inital catalog="+Str_LocalConfig[3].
           Trim();
       Sql_Connection=new System.Data.SqlClient.SqlConnection(Str_Connection);
       Sql_Command.Connection=Sql_Connection;
       Sql_Command.CommandType=System.Data.CommandType.StoredProcedure;

       Sql_Command.CommandText=ProcName;
       for(int i=0;i<Parm.Length;i++)
       {
        System.Data.SqlClient.SqlParameter PP=Sql_Command.Parameters.Add(Parm[i].ParamName,Parm[i].
         SQLType,Parm[i].Length);
        PP.Value =Parm[i].Value;
       }

       return Sql_Command.ExecuteReader();

      }
      public void ConnectionClose()
      {
       Sql_Connection.Close();
      }

     } 
    }


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/4/25 9:38:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 C/C++编程思想 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2025/2/2 11:56:38

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    66.406ms