■ 컬럼명 체크하기 예제

------------------------------------------------------------------------------------------------------------------------

using System;

 

string connectionString = "Data Source=d:\\arca.db;";

string tableName        = "COM_USER";

string columnName       = "NAME";

 

bool result = CheckColumnName(connectionString, tableName, columnName);

 

Console.WriteLine(result);

------------------------------------------------------------------------------------------------------------------------

 

■ 컬럼명 체크하기

------------------------------------------------------------------------------------------------------------------------

using System.Data.SQLite;

 

#region 컬럼명 체크하기 - CheckColumnName(connectionString, tableName, columnName)

 

/// <summary>

/// 컬럼명 체크하기

/// </summary>

/// <param name="connectionString">연결 문자열</param>

/// <param name="tableName">테이블명</param>

/// <param name="columnName">컬럼명</param>

/// <returns>컬럼명 체크 결과</returns>

public bool CheckColumnName(string connectionString, string tableName, string columnName)

{

    using(SQLiteConnection connection = new SQLiteConnection(connectionString))

    {

        connection.Open();

 

        var command = connection.CreateCommand();

 

        command.CommandText = string.Format("PRAGMA table_info({0})", tableName);

        

        var reader = command.ExecuteReader();

 

        int nameIndex = reader.GetOrdinal("Name");

 

        while(reader.Read())

        {

            if(reader.GetString(nameIndex).Equals(columnName))

            {

                connection.Close();

 

                return true;

            }

        }

 

        connection.Close();

    }

 

    return false;

}

 

#endregion

------------------------------------------------------------------------------------------------------------------------

 

Posted by icodebroker
TAG