none
WPF and MS Word Bookmarks RRS feed

  • Question

  • Hi there
    I am working on a project to create some documents (MS Word) where the template include lots of bookmarks wanted to replace all the bookmarks with values coming from different tables from the database.

    Bookmark name is same as database table columns name so
    In clientTable column name “clt_firstname”,”clt_gender”  ect. same as bookmark in MS word is also name as same “clt_firstname”,”clt_gender” 
    Is there a way where I can check before query the database where the name of the column exists in the data Content ?

    select *
    from information_schema.COLUMNS
    where column_name like '%name%'

    so I know which table to query to get the data instead of going through all the table to find then matching column.
    .

    I got tables eg.

    Customers
    Cus_FirstName
    Cus_Surname,
    Cus_gender
    Ect..

    Products
    Pro_Name
    Pro_UnitPrice
    Ect..

    Suppliers
    Sup_FirstName
    Sup_surname
    Sup_Telephone
    Ect..


    Ms Word template can have any of the bookmarks and requiring any database field information.

    Appreciate your help and assistance

     

    Monday, March 19, 2012 3:41 PM

Answers

  • Hi,

    you said:

    "so I know which table to query to get the data instead of going through all the table to find then matching column"

    When you start your programm, use that query:

    SELECT *
    FROM INFORMATION_SCHEMA.COLUMNS

    to get a list of all Tables and Colums available in the SQL Server

    You can remember that informaion for e.g. in a List<KeyValuePair> A KeyValuePair could be Key = TableName, Value = Column

    Then you can easily lookup the tablename you need to query later by searching throug the Values of your List<KeyValuePair> Collection.
    Just an Idea.

    Hope you understand

    Greets - Helmut


    Helmut Obertanner [http://www.obertanner.de] [http://www.outlooksharp.de]

    • Marked as answer by Rushdy Najath Tuesday, March 20, 2012 10:47 AM
    Tuesday, March 20, 2012 10:25 AM
    Answerer

All replies

  • Hello Rushdy Nadja,

    You can get this script to get all Columns of your Tables:

    SELECT * 
    FROM INFORMATION_SCHEMA.COLUMNS

    I would call this at AddIn startup and build a Directory with Table/Column Keypairs.


    Then you don't have to query the DB for each field.

    Greets - Helmut


    Helmut Obertanner [http://www.obertanner.de] [http://www.outlooksharp.de]

    Tuesday, March 20, 2012 7:02 AM
    Answerer
  • Sorry I did not understand clearly
    Would you please explain me bit more in detail  ?

    Thanks


    Tuesday, March 20, 2012 10:04 AM
  • Hi,

    you said:

    "so I know which table to query to get the data instead of going through all the table to find then matching column"

    When you start your programm, use that query:

    SELECT *
    FROM INFORMATION_SCHEMA.COLUMNS

    to get a list of all Tables and Colums available in the SQL Server

    You can remember that informaion for e.g. in a List<KeyValuePair> A KeyValuePair could be Key = TableName, Value = Column

    Then you can easily lookup the tablename you need to query later by searching throug the Values of your List<KeyValuePair> Collection.
    Just an Idea.

    Hope you understand

    Greets - Helmut


    Helmut Obertanner [http://www.obertanner.de] [http://www.outlooksharp.de]

    • Marked as answer by Rushdy Najath Tuesday, March 20, 2012 10:47 AM
    Tuesday, March 20, 2012 10:25 AM
    Answerer
  • thanks yes i got it..thanks a lot for your time
    Tuesday, March 20, 2012 10:47 AM