[ASP.net]数据访层

DbConnection.cs
None.gif using  System;
None.gif
using  System.Data.SqlClient;
None.gif
None.gif
namespace  DbControl
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// 数据库链接
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class DbConnection
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
//SQL数据库链接字符串
InBlock.gif
        private string _strSqlConnection = System.Configuration.ConfigurationSettings.AppSettings[ "SqlConnectionString" ];
InBlock.gif        
//XML文件链接字符串
InBlock.gif
        private string _strXmlConnection = string.Empty;
InBlock.gif
InBlock.gif        
public string ConnectionString
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _strSqlConnection;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this._strSqlConnection = System.Configuration.ConfigurationSettings.AppSettings[ value ];
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public SqlConnection SqlConnectionString
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return new SqlConnection( ConnectionString );
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public string XmlConnectionString
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._strXmlConnection;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this._strXmlConnection = value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public DbConnection()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// TODO: 在此处添加构造函数逻辑
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif


AppControl.cs
None.gif using  System;
None.gif
using  System.Data;
None.gif
using  System.Data.SqlClient;
None.gif
None.gif
namespace  DbControl
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// AppControl 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class SqlControl : DbConnection
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private SqlConnection _Conn;
InBlock.gif        
private SqlCommand _Cmd;
InBlock.gif
InBlock.gif        
public SqlControl()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// TODO: 在此处添加构造函数逻辑
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 打开数据库链接
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void Open()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this._Conn = this.SqlConnectionString;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _Conn.Open();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch ( System.Exception ex )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw ex;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 关闭数据库链接
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void Close()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this._Conn.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch( System.Exception ex )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw ex;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 运行SQL,返回DataTable数据
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="query">SQL语句</param>
ExpandedSubBlockEnd.gif        
/// <returns>返回DataTable</returns>

InBlock.gif        public DataTable RunSqlToDataTable( string query )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Open();
InBlock.gif            DataTable objDataTable 
= new DataTable();
InBlock.gif            SqlDataAdapter objAdapter 
= new SqlDataAdapter( query , _Conn );
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                objAdapter.Fill( objDataTable );
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch( System.Exception ex )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw ex;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return objDataTable;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行SQL语句,返回单个值
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="query">标准T-SQL语句</param>
ExpandedSubBlockEnd.gif        
/// <returns>返回string</returns>

InBlock.gif        public string RunSqlToResult( string query )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Open();
InBlock.gif            
this._Cmd = new SqlCommand( query,this._Conn );
InBlock.gif            System.Text.StringBuilder strResult 
= new System.Text.StringBuilder();
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                strResult.Append( 
this._Cmd.ExecuteScalar() );
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch( System.Exception ex )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw ex;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return strResult.ToString();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 运行单个SQL的相关操作
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="query">SQL语句</param>
ExpandedSubBlockEnd.gif        
/// <returns>返回AppControl</returns>

InBlock.gif        public SqlControl ExecuteNonQuery( string query )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Open();
InBlock.gif            _Cmd 
= new SqlCommand( query , _Conn );
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _Cmd.ExecuteNonQuery();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch( System.Exception ex )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw ex;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return this;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 按事务执行SQL语句数组
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="query">标准T-SQL语句数组</param>
ExpandedSubBlockEnd.gif        
/// <returns>返回AppControl</returns>

InBlock.gif        public SqlControl ExecuteNonQuery( string[] query )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Open();
InBlock.gif            
this._Cmd = new SqlCommand();
InBlock.gif            SqlTransaction objTran 
= this._Conn.BeginTransaction();
InBlock.gif            
this._Cmd.Connection = this._Conn;
InBlock.gif            
this._Cmd.Transaction = objTran;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
for ( int i=0 ; i<query.Length ; i++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this._Cmd.CommandText = query[i];
InBlock.gif                    
this._Cmd.ExecuteNonQuery();
ExpandedSubBlockEnd.gif                }

InBlock.gif                objTran.Commit();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch( System.Exception ex )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                objTran.Rollback();
InBlock.gif                
throw ex;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return this;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 执行SQL语句,返回SqlDataReader.
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="query">标准SQL语句</param>
ExpandedSubBlockEnd.gif        
/// <returns>返回DataReader</returns>

InBlock.gif        public SqlDataReader RunSqlToDataReader( string query )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Open();
InBlock.gif            
this._Cmd = new SqlCommand( query , this._Conn );
InBlock.gif            SqlDataReader objDataReader;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                objDataReader 
= this._Cmd.ExecuteReader();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch( System.Exception ex )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw ex;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return objDataReader;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 运行存储过程(有参数,无输出)
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="procedureName">存储过程名</param>
InBlock.gif        
/// <param name="parameters">存储过程参数数组</param>
ExpandedSubBlockEnd.gif        
/// <returns>返回AppControl</returns>

InBlock.gif        public SqlControl RunProcedure( string procedureName,SqlParameter[] parameters )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Open();
InBlock.gif            
this._Cmd = this.MakeProcedure( procedureName,parameters );
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this._Cmd.ExecuteNonQuery();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch( System.Exception ex )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw ex;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return this;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 运行存储过程(无参数,无输出)
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="procedureName">存储过程名</param>
ExpandedSubBlockEnd.gif        
/// <returns>返回AppControl</returns>

InBlock.gif        public SqlControl RunProcedure( string procedureName )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Open();
InBlock.gif            
this._Cmd = this.MakeProcedure( procedureName,null );
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this._Cmd.ExecuteNonQuery();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch( System.Exception ex )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw ex;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return this;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 运行存储过程(无参数,有输出)
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="procedureName">存储过程名</param>
InBlock.gif        
/// <param name="parametersOutput">存储过程输出参数数组</param>
ExpandedSubBlockEnd.gif        
/// <returns>返回AppControl</returns>

InBlock.gif        public SqlControl RunProcedure( string procedureName,ref SqlParameter[] parametersOutput )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Open();
InBlock.gif            
this._Cmd = this.MakeProcedure( procedureName,parametersOutput );
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this._Cmd.ExecuteNonQuery();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch( System.Exception ex )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw ex;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return this;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 运行存储过程(有参数,无输出)
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="procedureName">存储过程名</param>
InBlock.gif        
/// <param name="parameters">存储过程参数数组</param>
ExpandedSubBlockEnd.gif        
/// <returns>返回DataTable</returns>

InBlock.gif        public DataTable RunProcedureToDataTable( string procedureName,SqlParameter[] parameters )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Open();
InBlock.gif            
this._Cmd = this.MakeProcedure( procedureName,parameters );
InBlock.gif            DataTable objDataTable 
= new DataTable();
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this._Cmd.ExecuteNonQuery();
InBlock.gif                SqlDataAdapter objAdapter 
= new SqlDataAdapter( this._Cmd );
InBlock.gif                objAdapter.Fill( objDataTable );
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch( System.Exception ex )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw ex;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return objDataTable;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 运行存储过程(有参数,有输出)
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="procedureName">存储过程名</param>
InBlock.gif        
/// <param name="parametersInput">存储过程输入参数数组</param>
InBlock.gif        
/// <param name="parametersOutput">存储过程输出参数数组</param>
ExpandedSubBlockEnd.gif        
/// <returns>返回DataTable</returns>

InBlock.gif        public DataTable RunProcedureToDataTable( string procedureName,SqlParameter[] parametersInput,ref SqlParameter[] parametersOutput )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Open();
InBlock.gif            
this._Cmd = this.MakeProcedure( procedureName,parametersInput );
InBlock.gif            
if ( parametersOutput != null )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
foreach( SqlParameter parameter in parametersOutput )
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this._Cmd.Parameters.Add( parameter );
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            DataTable objDataTable 
= new DataTable();
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this._Cmd.ExecuteNonQuery();
InBlock.gif                SqlDataAdapter objAdapter 
= new SqlDataAdapter( this._Cmd );
InBlock.gif                objAdapter.Fill( objDataTable );
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch( System.Exception ex )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw ex;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return objDataTable;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 运行存储过程(无参数)
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="procedureName">存储过程名</param>
ExpandedSubBlockEnd.gif        
/// <returns>返回DataTable</returns>

InBlock.gif        public DataTable RunProcedureToDataTable( string procedureName )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Open();
InBlock.gif            
this._Cmd = this.MakeProcedure( procedureName,null );
InBlock.gif            DataTable objDataTable 
= new DataTable();
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this._Cmd.ExecuteNonQuery();
InBlock.gif                SqlDataAdapter objAdapter 
= new SqlDataAdapter( this._Cmd );
InBlock.gif                objAdapter.Fill( objDataTable );
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch( System.Exception ex )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw ex;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return objDataTable;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 建立存储过程
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="procedureName">存储过程名</param>
InBlock.gif        
/// <param name="parameters">存储过程参数数组</param>
ExpandedSubBlockEnd.gif        
/// <returns>返回AppControl</returns>

InBlock.gif        private SqlCommand MakeProcedure( string procedureName,SqlParameter[] parameters )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            SqlCommand objCmd 
= new SqlCommand( procedureName,this._Conn );
InBlock.gif            objCmd.CommandType 
= CommandType.StoredProcedure;
InBlock.gif            
if ( parameters != null )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
foreach( SqlParameter sqlParamet in parameters )
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    objCmd.Parameters.Add( sqlParamet );
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
return objCmd;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 多表查询
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="query">标准SQL语句集</param>
ExpandedSubBlockEnd.gif        
/// <returns>返回DataSet</returns>

InBlock.gif        public DataSet RunSqlToDataSet( string[] query )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Open();
InBlock.gif            DataSet objDataSet 
= new DataSet();
InBlock.gif            SqlDataAdapter objAdapter 
= new SqlDataAdapter();
InBlock.gif            
this._Cmd = new SqlCommand();
InBlock.gif            
this._Cmd.Connection = this._Conn;
InBlock.gif            objAdapter.SelectCommand 
= this._Cmd;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
for ( int i=0 ; i<query.Length ; i++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    objAdapter.SelectCommand.CommandText 
= query[i];
InBlock.gif                    objAdapter.Fill( objDataSet.Tables.Add() );
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch( System.Exception ex )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw ex;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return objDataSet;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/HD/archive/2005/03/30/127905.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值