첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

▶ 컬럼명 체크하기 예제

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);

 

728x90

 

▶ 컬럼명 체크하기

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
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요