我努力地啃着书本知识, 可以是还是没有什么成功, 在网上东拉西凑的,还是没有成功
那我再努力吧


using System;
using System.Data;
using System.Data.SqlClient;

namespace DemoBIMS
{
    
/// <summary>
    
/// Summary description for SqlTools.
    
/// </summary>

    public class SqlTools
    
{
        
public SqlTools()
        
{
            
//
            
// TODO: Add constructor logic here
            
//
        }

        
private SqlConnection _sqlConn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["strConn"]);
        
private SqlConnection _sqlNVS=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["strNVS"]);
        
private DataSet tmpDS=null;
        
public DataSet GetData(string strSQL)
        
{
            SqlDataAdapter _sqlDA
=new SqlDataAdapter(strSQL,_sqlConn);
            
this.tmpDS=new DataSet();
            
try
            
{
                _sqlDA.Fill(
this.tmpDS,"_tmp");
                
return tmpDS;
            }

            
catch(Exception)
            
{
                
return null;
            }

            
finally
            
{
                _sqlDA.Dispose();
                
this._sqlConn.Close();
            }

        }

        
public void Update2Source(DataSet ds,string strSelCMD)
        
{
            SqlDataAdapter _sqlDA
=new SqlDataAdapter();
            _sqlDA.SelectCommand
=new SqlCommand(strSelCMD,this._sqlConn);
            SqlCommandBuilder cb
=new SqlCommandBuilder(_sqlDA);
            
try
            
{
                _sqlDA.Update(ds,
"_tmp");
                ds.AcceptChanges();
            }

            
catch(Exception)
            
{
                
//
            }

            
finally
            
{
            _sqlDA.Dispose();
            
this._sqlConn.Close();
            }

        }

    
        
public int SqlExecuteNonQuery(string strSQL)
        
{
            SqlCommand _sqlCMD
=new SqlCommand(strSQL,this._sqlConn);
            
this._sqlConn.Open();
            
try
            
{
                
return _sqlCMD.ExecuteNonQuery();
            }

            
catch(Exception)
            
{
                
this._sqlConn.Close();
                
return 0;
            }

            
finally
            
{
                _sqlCMD.Dispose();
                
this._sqlConn.Close();
            }

        }

        
public int GetDataReader(string strSQL)
        
{
            SqlCommand _sqlCMD
=this._sqlConn.CreateCommand();
            _sqlCMD.CommandText
=strSQL;
            
try
            
{
                
this._sqlConn.Open();
                
return (int) _sqlCMD.ExecuteScalar();
            }

            
catch(Exception)
            
{
                
this._sqlConn.Close();
                _sqlCMD.Dispose();
                
return 0;
            }

            
finally
            
{
                
this._sqlConn.Close();
                _sqlCMD.Dispose();
            }

            
        }

        
public bool CheckDataSetIsNull(System.Data.DataSet ds)
        
{
            
if (ds==null)
                
return true;
            
else
                
return false;
        }

        
public string [] SplitDouble(double d)
        
{
            
string _tmpStr=d.ToString();
            
string [] _Str=_tmpStr.Split(char.Parse("."));
        
//    uint int16=Convert.ToInt16(_Str[0]);
            return _Str;
        }

        
public DataSet GetDetailSMNUM(int SMNUM)
        
{
            
string strSQL="SELECT * FROM DNOTE WHERE SMNUM=@SMNUM";
            SqlDataAdapter _sqlDA
=new SqlDataAdapter();
            _sqlDA.SelectCommand
=new SqlCommand(strSQL,this._sqlNVS);
//            _sqlDA.SelectCommand.CommandType=CommandType.Text;
            _sqlDA.SelectCommand.Parameters.Add("@SMNUM",SqlDbType.Int,4,"SMNUM");
            _sqlDA.SelectCommand.Parameters[
"@SMNUM"].Value=SMNUM;
            
            
//_sqlDA.SelectCommand.Connection=this._sqlNVS;
            this.tmpDS=new DataSet();
            
try
            
{
                _sqlDA.Fill(
this.tmpDS,"_tmp");
                
return tmpDS;
            }

            
catch(Exception)
            
{
                
return null;
            }

            
finally
            
{
                
this._sqlConn.Close();
                _sqlDA.Dispose();
            }

        }

    }

}