■ 컬럼명을 체크하는 방법을 보여준다.
▶ 컬럼명 체크하기 예제 (XAML)
1 2 3 4 5 6 7 8 9 10 11 |
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); |
▶ 컬럼명 체크하기 (XAML)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
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 |