All pastes #72481 Raw Edit

Something

public text v1 · immutable
#72481 ·published 2006-06-26 21:49 UTC
rendered paste body
using System;
using System.Collections;
using System.Text;
using System.Reflection;
using System.Data.SqlClient;

namespace nTier
{
    public class Base
    {
        public static void SetObject(object Object)
        {
          
            SqlCommand objCommand = nTier.Data.MssqlDataConnection.objConnection.CreateCommand();
            object[] objArray = null;
            StringBuilder objBuilder = new StringBuilder();
            PropertyInfo[] objPropertyIndex = Object.GetType().GetProperties(BindingFlags.Public|BindingFlags.Instance);
            PropertyInfo objPropertyInfo = null;
            //string strValue = "";
            //string strName = "";
            string strTablename = "TesT";
            objBuilder.Append("INSERT INTO ");
            objBuilder.Append(strTablename);
            objBuilder.Append("(");
            for (int iIndex = 0; iIndex < objPropertyIndex.Length; iIndex++)
            {
                objPropertyInfo = objPropertyIndex[iIndex];
                if (objPropertyInfo.CanRead && objPropertyInfo.CanWrite)
                {
                    object[] objPropertyInfoAttribute = objPropertyInfo.GetCustomAttributes(true);
                    for (int iAttributeIndex = 0; iAttributeIndex < objPropertyInfoAttribute.Length; iAttributeIndex++)
                    {
                        if (objPropertyInfoAttribute[iAttributeIndex] is nTier.Attributes.Property)
                        {
                            if (((nTier.Attributes.Property)objPropertyInfoAttribute[iAttributeIndex]).IsPrimaryKey != true)
                            {

                                objBuilder.Append(objPropertyInfo.Name);
                                if (iAttributeIndex != objPropertyInfoAttribute.Length)
                                    objBuilder.Append(",");
                            }
                        }
                    }
                }
            }
            objCommand.CommandText = objBuilder.ToString();
            string strCommand = objCommand.CommandText;
        }
    }
}