string query="SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'calendar'"; string conn_string="[YOUR DB CONNECTION STRING]"; try { using (SqlCeConnection conn = new SqlCeConnection(conn_string)) { conn.Open(); using (SqlCeCommand cmd = new SqlCeCommand(query, conn)) { SqlCeDataReader reader=cmd.ExecuteReader(); while (reader.Read()) { int fc=reader.FieldCount; for (int i = 0; i < fc; ++i) { Console.WriteLine("DB Column Header: {0}", reader.GetValue(i)); } } } conn.Close(); } } catch (Exception ex) { Console.WriteLine("Error executing: {0}", query); Console.WriteLine(ex.ToString()); }
One interesting observation is that if one has a column named "national" within the "calendar" table and tries to retrieve it using "SELECT national from calendar", the query will fail as it seems that "national" may be a keyword in the SQLCE (which i am not sure at this point).
No comments:
Post a Comment