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

public class SqlData
{
    public SqlData()
    {
    }
    
    // connection string
    private string _sConnectionString = string.Empty;
    public string DataConnection
    {
        get { if (_sConnectionString == string.Empty || _sConnectionString == null)
            throw new Exception("don't know connection string");
            //return ConfigurationManager.ConnectionStrings["DataConnection"].ConnectionString;
        else
            return _sConnectionString;}
        protected set { _sConnectionString = value; }
    }

    // table name
    private string _sTableName = string.Empty;
    public string TableName
    {
        get { return _sTableName; }
        protected set { _sTableName = value; }
    }

    // primary key columns name
    private string[] _arPrimaryKeyColumnNames = { };
    public string[] PrimaryKeyColumnNames
    {
        get { return _arPrimaryKeyColumnNames; }
        protected set { _arPrimaryKeyColumnNames = value; }
    }

    // set primary keys
    protected void SetPrimaryKeys(DataTable dataTable)
    {
        DataColumn[] keys = new DataColumn[PrimaryKeyColumnNames.Length - 1];

        for (int i = 0; i < PrimaryKeyColumnNames.Length; i++)
        {
            keys[i] = dataTable.Columns[PrimaryKeyColumnNames[i]];
        }

        dataTable.PrimaryKey = keys; 
    }
}