[help]how to know whether the given column exists in the table or not????

Hi all, can anyone tell me how to write a C# code help me to know whether the given field exists.
If it doesnt exists then i want to alter the table to include this column also
I am able to write the code for alter table but i m not sure how do i check for its existence/nonexistence
My Altering code
{color:#800000}cmd.CommandText = "alter table " + row.ToString() + " add(" + sQuality + " varchar2(50), " +
sTimeStamp + " varchar2(50), " +
sValue + " varchar2(50))";
cmd.CommandType = CommandType.Text;
cmd.ExecuteReader();
{color}

Just iterate the datatable after completion and check for your column.
        public static DataTable MaterializeTableStructure(string _connectionString, string _tableName)
            DataSet ds = null;
            using (OracleConnection _oraconn = new OracleConnection(_connectionString))
                try
                    _oraconn.Open();
                    string sql = "SELECT COLUMN_NAME, DATA_TYPE, NULLABLE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE FROM user_tab_columns where table_name='" + _tableName + "'";
                    using (OracleCommand cmd = new OracleCommand(sql, _oraconn))
                        cmd.CommandType = CommandType.Text;
                        using (OracleDataAdapter da = new OracleDataAdapter(cmd))
                            ds = new DataSet("MaterializeTableStructure");
                            da.Fill(ds);
                catch (OracleException _oraEx)
                    throw (_oraEx); // Actually rethrow
                catch (System.Exception _sysEx)
                    throw (_sysEx); // Actually rethrow
                finally
                    if (_oraconn.State == ConnectionState.Broken || _oraconn.State == ConnectionState.Open)
                        _oraconn.Close();
            if (ds != null)
                return ds.Tables[0];
            else
                return null;
        }r,
dennis

Similar Messages

  • Without hear again, how to know whether i heard a podcast in the past ?

    Hi guys
    I listen to a lot of podcasts from many different DJ. My question is: without hear it again, how to i know whether i heard this podcast already in the past?
    I hope there are some kind of app that can help me? I don’t want to use the book ^^
    Any ideas guys?

    Not solved.

  • How to know whether a particular query is using the aggregates

    hi all....
    im very new to this group so plz help me out.....anyway hi to all ....
    There are many aggreegates are there but how to know which query is using perticular a?gregates

    Hi,
    use query monitor screen RSRT and select the option execute + debug . and u can have the option of checking display aggreagates for that query!
    cheers,
    ravi

  • How to Load data for extra columns exist in the dest schema....

    Hi Experts,
    Please help me.
    I need to replicate data from SchemaA to SchemaB.
    SchemaB has 3 extra columns. Two are varchar2 type and other is Integer type.
    I need to replicate the data from SchemaA to SchemaB in the same database.
    When ever i inserted the data in SchemaA, The extra columns should be populated with some default data.
    And if we did any update on SchemaA then the extra columns on SchemaB should be populated with other Data.
    I wrote some DML_HANDLER but it always populating same data.
    I dont know ow to handle this type of situation.
    my Handler is:
    CREATE OR REPLACE PROCEDURE dml_handler(in_any in sys.anydata)
    IS
    lcr SYS.LCR$_ROW_RECORD;
    rc PLS_INTEGER;
    object_owner VARCHAR2(30);
    BEGIN
    rc := in_any.GETOBJECT(lcr);
    object_owner := lcr.GET_OBJECT_OWNER();
    IF lcr.get_object_owner() = 'SchemaB' THEN
    lcr.add_column('new','SHIP_DATE',sys.anydata.convertvarcahr2('N'));
    lcr.add_column('new','SHIP_ZONE',sys.anydata.convertvarchar2('N'));
    lcr.add_column('new','SHIP_REACH_BY_DATE',sys.anydata.convertnumber(1));
    lcr.EXECUTE(TRUE);
    END IF;
    END;
    BEGIN
    DBMS_APPLY_ADM.SET_DML_HANDLER
    (object_name => 'SchemaB.TAB_TEST',
    object_type => 'TABLE',
    operation_name => 'INSERT',
    error_handler => FALSE,
    user_procedure => 'STRMADMIN.DML_HANDLER');
    END;
    On extra columns in SChemaB
    if its a first insert then the default values are (N,N,1).
    If we did any update the values should be (Y,Y,2)
    Post any script or give me some idea.
    Thanks,
    Ray
    Edited by: user7423698 on Mar 3, 2009 6:12 PM

    CREATE OR REPLACE PROCEDURE dml_handler (
    in_any IN SYS.ANYDATA
    IS
    lcr sys.lcr$_row_record;
    rc PLS_INTEGER;
    cmd_type VARCHAR2 (30);
    BEGIN
    rc := in_any.getobject (lcr);
    cmd_type := lcr.get_command_type;
    IF cmd_type = 'INSERT'
    THEN
    lcr.set_values ('new', lcr.get_values ('new', 'N'));
    lcr.add_column ('new', 'type', sys.anydata.convertchar ('I'));
    lcr.set_values ('old', NULL);
    lcr.add_column ('new', 'time', sys.anydata.converttimestamp (systimestamp));
    lcr.execute (TRUE);
    END IF;
    END;
    Set the DML handler for INSERT and write a similar one for UPDATE.

  • How to know whether my oracle 10g instalation in unicode supported or not

    Hi
    i am new to oracle. I have installed Oracle 10g client and server.
    I want to know whether the database created can store unicode data/arabic data.
    Please guide me how can i find whether unicode support is on for my db or not.
    The outputs of some of the queries run by me are as follows:
    SQL> HOST ECHO $NLS_LANG;
    $NLS_LANG
    SQL> HOST ECHO %NLS_LANG%;
    %NLS_LANG%
    SQL> @.[%NLS_LANG%];
    SP2-0310: unable to open file ".[AMERICAN_AMERICA.WE8MSWIN1252]"
    SQL> select cust_eng_name,cust_arb_name from custmast;
    select cust_eng_name,cust_arb_name from custmast
    ERROR at line 1:
    ORA-00942: table or view does not exist
    Please reply me asap.

    user10817093 wrote:
    1. Yeh that is the thing I want. What are the other steps that i need to do with my Oracle Client/Server for unicode support.
    Where i am getting trouble is the Oracle Client/Server unicode support.
    And how to decide what character set will suite me best.1. If your application is going to be a "true" Unicode application, you can set the NLS_LANG registry/environment setting on your clients to ".UTF8" to enable true Unicode support.
    2. Your database needs to support Unicode, too.
    The recommended database character set for this in 10g is "AL32UTF8".
    If you currently have a single-byte database character set (WE8MSWIN1252), you need to decide how to get this done.
    If you can simply create a new database using the "AL32UTF8" character set, this would be the easiest way.
    There are several documents available (e.g. on Oracle MetaLink) that describe in detail how to convert the character set of an existing database. Depending on your data this can be a tedious task involving several steps, so may be creating a new database and exporting/importing the data might be the simplest choice if you need to migrate some existing data.
    The recommended national character set is "AL16UTF16", by the way, but that shouldn't matter that much once you have a Unicode enabled database using "AL32UTF8" as database character set.
    2. How to set/retrive the "Database Character Set" and "National Character Set". This has already been answered partly. Retrieve:
    Database Character Set:
    SELECT VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER = 'NLS_CHARACTERSET';National Character Set:
    SELECT VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER = 'NLS_NCHAR_CHARACTERSET';In most of the cases you can't just simply set/alter the character sets, as outlined above.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • How to know whether alternate layout is created on a document or not?

    Hi,
    I'm working on a plugin for InDesign CS6 and need to find out whether a particular document has alternate layout applied on it or not. Secondly I also want to get the notification whenever alternate layout is being created on a document.
    Can anyone please help me out.

    I'm not into the SDK, but according to the Javascript DOM, alternate layouts are part of Sections -- the section property 'alternateLayoutLength', for example, is "[t]he number of pages in the alternate layout section".
    Perhaps that gives you a clue of where to look?

  • How to know whether a file is opened  or not ?

    Hi all,
    How to know whether a file is opened by its editor or not ? File may be any of the type.

    There are platform-dependent commands that tell whether a file (or directory, port etc.) is used by which processes.
    [oracle@izsak ~]$ fuser .
    .:                    9299c
    [oracle@izsak ~]$ ps -p  9299 -f
    UID        PID  PPID  C STIME TTY          TIME CMD
    oracle    9299  9298  0 Apr25 pts/0    00:00:00 -bash
    [oracle@izsak ~]$ ls -l $fn
    -rw-r-----  1 oracle oinstall 111215876 Apr 25 19:05 /opt/oracle/product/AS/10g/R2/opmn/logs/OC4J~ebank~default_island~1
    [oracle@izsak ~]$ fuser $fn
    /opt/oracle/product/AS/10g/R2/opmn/logs/OC4J~ebank~default_island~1:  3746  3747  3748  3749  3750  3751  3752  3753  3754  3755  3756  3758  3761  3762  3765  3767  3769  3770  3771 18638 21605 21743 21744 21745 22140 22143
    [oracle@izsak ~]$ ps -p 3746 -f
    UID        PID  PPID  C STIME TTY          TIME CMD
    oracle    3746 26427  0 Apr23 ?        00:00:01 /opt/oracle/product/AS/10g/R2/jdk/bin/java -server -Djava.security.policy=/opt...

  • How to test if a column exists in a table

    Hello,
    Using SQL or PL/SQL how do I test if a column exists in a table. For example,
    if column_aa exists in table_1
    then do this....
    else do that....
    Thank you.

    Set ServerOutput On;
    CREATE Table a_Test (
    Col1 NUMBER
    , Col2 NUMBER )
    DECLARE
    lnCol1 NUMBER ;
    lnCol7 NUMBER ;
    PROCEDURE TestColumn( acColName IN VARCHAR2 )
    IS
    lnColX NUMBER ;
    NoColumnExists EXCEPTION;
    PRAGMA EXCEPTION_INIT(NoColumnExists, -904);
    BEGIN
    EXECUTE IMMEDIATE
    'SELECT Max('|| acColName||') FROM a_Test WHERE RowNum = 0'
    INTO lnColX ;
    DBMS_OUTPUT.Put_Line('Column: '||acColName||' exists.');
    EXCEPTION
    WHEN NoColumnExists THEN
    DBMS_OUTPUT.Put_Line('Column: '||acColName||' NOT exists.');
    WHEN Others THEN
    DBMS_OUTPUT.Put_Line( SqlCode ||' '||SqlErrM );
    END
    BEGIN
    DBMS_OUTPUT.Enable ;
    TestColumn( 'Col1') ;
    TestColumn( 'Col2') ;
    TestColumn( 'Col7') ;
    END
    DROP Table a_Test;

  • How to know whether the Content Type at Library level is Inheriting Parent Content type or not Using Powershell?

    Hi,
    How to know whether the Content Type at Library level is Inheriting Parent Content type or not using Powershell?
    Is there any property for that? Or Do I need to compare the Content type Id's at Site collection level and Library level?
    Any help would be greatly appreciated.
    Thank you,
    AA.

    Hi Ashok,
    For a content type, there is an attribute called Inherits, the value of this attribute determines whether the content type inherits fields from its parent content type when it is created.
    If Inherits is TRUE, the child content type inherits all fields that are in the parent, including fields that users have added.
    If Inherits is FALSE or absent and the parent content type is a built-in type, the child content type inherits only the fields that were in the parent content type when SharePoint Foundation was
    installed. The child content type does not have any fields that users have added to the parent content type.
    More information, please refer to the link:
    https://msdn.microsoft.com/en-us/library/office/aa544268.aspx?f=255&MSPPError=-2147217396
    Best Regards,
    Wendy
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How to know whether my Windows Phone 8.1 App is Associated with the store or not?

    How to know whether my Windows Phone 8.1 App is Associated with the store or not? 
    I have an Windows Phone 8 app already in the store , Now i upgraded it to 8.1 it got upgraded to Windows Phone Silverlight 8.1.
    Now iam trying to use Single Sign on feature on this app but it is showing the error message like
    the App is not Configured correctly i followed the process from  Signing users in to OneDrive
    please guide me how to do this?
    Mohan Rajesh Komatlapalli

    You should post to publish forum.

  • How to know whether the javascript is disabled or not while loading the jsp

    Hi,
    My query is like how to know whether the javascript is disabled or not while loading the Application main JSP in Mozilla browser.
    I want some Java code or JavaScript code.

    To the point, just let JS fire a specific HTTP request inside the same session.
    This can be done in several ways. 1) Create a hidden <img> element and set the `src` attribute so that it will request a (fake) image from the server. The server just have to intercept on this specific request. 2) Fire an ajaxical request and let the server intercept on it. You can use a Filter for this which sets a token in the session scope to inform that the client has JS enabled.

  • How to know whether a method is thread-safe through the java-doc?

    In some book, it says that SAXParserFactory.newSAXParser() is thread-safe,but in the java-doc,it doesn't say that.
    newSAXParser
    public abstract SAXParser newSAXParser()
    throws ParserConfigurationException,
    SAXExceptionCreates a new instance of a SAXParser using the currently configured factory parameters.
    Returns:
    A new instance of a SAXParser.
    Throws:
    ParserConfigurationException - if a parser cannot be created which satisfies the requested configuration.
    SAXException - for SAX errors.
    I want to know, how to know whether a method is thread-safe?

    System.out is a PrintStream object. None of the methods there use the synchronized modifier, but if you look in the source code, you will find out it is thread-safe, because it will use synchronized blocks whenever it writes some text.
    The source code is in the src.jar file which you can extract.
    I didn't find any comments about that PrintStream is thread-safe in the API.

  • How to know whether the current database is using a password file or not?

    How to know whether the current database is using a password file or not?

    The remote_password_file is the parameter that determines if you can use or not a password file. The values this parameter can have are NONE, SHARED, EXCLUSIVE. It is pretty obvious, if it is set to either SHARED or EXCLUSIVE the oracle instance has enabled the access through a password file for the SYSDBA and SYSOPER roles.
    ~ Madrid

  • How to know whether the phone is replaced or not?

    Dear All,
    Please help in how to know whether Iphone 5 is replaced or not? I came to know that on replacement, imei number gets changed. please make me aware.

    Nobody here can make you aware.  You need to contact Apple directly.

  • How to know whether any item value got changed

    How to know in Apex whether any form item got changed. That will help me to know when the user will be pressing the "Apply Changes" button and I will popuplate the "User Modifed" and "Date Modifed" column values in the table. For now, I dont want to write database triggers, but to implement it at application level.

    Hi Deb
    For a really good explanation of the naming /numbering of tabular form items see Patrick Wolf's blog on the matter.
    http://www.inside-oracle-apex.com/which-tabular-form-column-is-mapped-to-which-apex_applicationg_fxx-array/
    He also gives a simple example of using check-boxes in tabular forms here
    http://www.inside-oracle-apex.com/checkboxes-in-tabular-forms-the-easy-way/
    You will notice in his example, that the apex_application.g_f40 is specifically named as 40 - a high number assuming that you don't have more than 39 editable columns in you tabular form - shown in the name="f40" code.
    <input type="checkbox" #ADMIN_USER_CHECKBOX# value="#ROWNUM#" name="f40" id="f40_#ROWNUM#"/>#ADMIN_USER_CHECKBOX#
    In essence the columns are numbered (only the editable ones) in the order in which they appear in the select statement - so the first editable column will be f(01), next f(02) etc - except where the column is specifically named - in this case f(40).
    I had a situation where I wanted to programatically stamp the user's name into a column depending on whether the user checked a check-box in each row.
    But if the column is editable and visible, then the user is free to type into this cell - this I wanted to avoid.
    Something that took me a while to work out is that you can hide an editable column - so it can updated by your procedure code - not by the user!
    The way to solve this is to have the sql statement select the relevant column twice - the first one is the editable one and hidden, and the second copy is a normal report column - displayed but not editable.
    I used Patrick's example in the link above to set up my tabular form with the first column as a check-box.
    The user then marks the desired rows by clicking in the check-box and submits / saves.
    The procedure then detects which rows have been checked - updates the editable (but hidden) database column, and then re-displays the result - with the second copy of the same column now showing the updated value!
    I hope this helps.
    Look at Patrick's other postings - they are so helpful.
    Mike

Maybe you are looking for

  • Looking for a specific country

    Hey guys, I was just wondering if Ovi maps for Armenia is available. I updated to 3.06, but I could have sworn to have seen it available for download before updating. When I check in Ovi suite now, it is not available. Solved! Go to Solution.

  • Import / export memory ID

    Hello. While customizing WM screens I noticed that using the memory ID / parameter ID doesn't work for me. I get sy-subrc 4 even though I made set/export before that. Examples: 1. export gv_matnr to memory id '/XLRF/4100'.     import gv_matnr from me

  • What is the shortcut Out Point for FCP?

    In Motion if your media is highlighted on the timeline your able to just press "I" or "O" What is it in FCP?

  • Just shuts down!

    Hi, I have just purchased a 27" imac 3.06 and transferred everything over from my 24". But It seems that the 27" has some issues! Apart from the fact it seems hard to start from sleep, it has now started closing down "pages" when I'm half way through

  • OS 1.0.5.2304 Is Here

    OS 1.0.5.2304 is ready for download. I'm downloading it now. Just realized there is another thread on this. http://supportforums.blackberry.com/t5/BlackBerry-PlayBook/BlackBerry-Playbook-upgrade-OS-v1-0-5-230... http://supportforums.blackberry.com/t