唐朝程序员

我来自唐朝

DataHelper

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

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

        
public static string ConnectionString=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
    
        
GetDataSet

        
#region ExecCommand
        
public static int ExecCommand(SqlCommand sqlcom)
        
{
            SqlConnection conn
=new SqlConnection(ConnectionString);
            sqlcom.Connection 
=conn;
            conn.Open();
            
try
            
{
                
int rtn=sqlcom.ExecuteNonQuery();
                
return rtn;
            }

            
catch(Exception ex) 
            
{
                
throw ex;                
            }

            
finally
            
{
                conn.Close();
            }

            
return 0;

        }

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

        
#endregion

        
        
ExecuteScalar

        
ExecSPCommand

        
ExecSPDataSet

        
DbType

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

        }

        
#endregion


        
InsertTable

        
DeleteTable

        
updateRow

        
deleteRow

        
midifyRow

        
insertRow
    }

}

2..调用范例
        Insert

        
Update

        
Delete

posted on 2006-09-30 09:30  唐朝程序员  阅读(255)  评论(0编辑  收藏  举报

导航