How to get column name in string query RRS feed

  • Question

  • User-1569093213 posted

    i have taken two dimensional array like

      string[,] tableArray = new string[67, 2]{

    {"Tablename", "Create TABLE  xyz([PrtId] COUNTER PRIMARY KEY NOT NULL,[PName] TEXT,[PValue] NUMBER)"}


    Now What i am doint heare i am reading the database table schema and checking out for column name and its count...here what i have to do is i want to take the column count from above  query and column count from database table..if there is mismatch in column count then i need to alter that particular table by adding a column..so how can i get the column count and its name from above query..or should i split it

    suggest me some solution

    Wednesday, May 6, 2015 2:02 AM

All replies

  • User753101303 posted


    You could parse the query (take the field list, split on ",", parse column definition) or you could do this the other way round that is to define columns using a more specialized data structure (maybe reusing DataColumn) that can already be easily consumed (even possible using the exact same datatable than the one you have when querying the schema fore the existing database) and generate the SQL query from that...

    Or another simplest option that could perhaps work would be to just have a version number inside your db so that you can just apply the statements allowing to upgrade your db to the next version...

    Or maybe by checking your db schema agaisnt another reference db (allowing to get both schema as datatables) etc...

    Wednesday, May 6, 2015 4:19 AM