DataHelper

1.建一个通用的处理数据的类
DataHelper using  System;
DataHelper
using  System.Data;
DataHelper
using  System.Data.SqlClient;
DataHelper
using  System.Text;
DataHelper
namespace  Document
DataHelper
{
DataHelper    
/// <summary>
DataHelper    
/// Summary description for DataHelper.
DataHelper    
/// </summary>

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

DataHelper        
public static string ConnectionString=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
DataHelper    
DataHelper        
GetDataSet
DataHelper
DataHelper        
#region ExecCommand
DataHelper        
public static int ExecCommand(SqlCommand sqlcom)
DataHelper        
{
DataHelper            SqlConnection conn
=new SqlConnection(ConnectionString);
DataHelper            sqlcom.Connection 
=conn;
DataHelper            conn.Open();
DataHelper            
try
DataHelper            
{
DataHelper                
int rtn=sqlcom.ExecuteNonQuery();
DataHelper                
return rtn;
DataHelper            }

DataHelper            
catch(Exception ex) 
DataHelper            
{
DataHelper                
throw ex;                
DataHelper            }

DataHelper            
finally
DataHelper            
{
DataHelper                conn.Close();
DataHelper            }

DataHelper            
return 0;
DataHelper
DataHelper        }

DataHelper        
public static int ExecCommand(string sql)
DataHelper        
{
DataHelper            
if (sql.EndsWith(",")) sql=sql.Substring(0,sql.Length-1);
DataHelper        
DataHelper            SqlCommand sqlcom
=new SqlCommand(sql);
DataHelper            
return ExecCommand(sqlcom);                
DataHelper        }

DataHelper        
#endregion

DataHelper        
DataHelper        
ExecuteScalar
DataHelper
DataHelper        
ExecSPCommand
DataHelper
DataHelper        
ExecSPDataSet
DataHelper
DataHelper        
DbType
DataHelper
DataHelper        
#region UpdateTable
DataHelper        
public static void UpdateTable(DataTable dt,string TableName,string KeyName)
DataHelper        
{
DataHelper            
foreach(DataRow dr in dt.Rows)
DataHelper            
{
DataHelper                updateRow(dr,TableName,KeyName);
DataHelper            }

DataHelper        }

DataHelper        
#endregion

DataHelper
DataHelper        
InsertTable
DataHelper
DataHelper        
DeleteTable
DataHelper
DataHelper        
updateRow
DataHelper
DataHelper        
deleteRow
DataHelper
DataHelper        
midifyRow
DataHelper
DataHelper        
insertRow
DataHelper    }

DataHelper}

2..调用范例
DataHelper          Insert
DataHelper
DataHelper        
Update
DataHelper
DataHelper        
Delete

你可能感兴趣的:(Data)