in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

What is the quickest way to init a specified field for all rows in c1ExpressTable?

Last post 04-11-2008 2:32 AM by AndrewSorokin. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 04-10-2008 3:05 AM

    What is the quickest way to init a specified field for all rows in c1ExpressTable?

    Hi

    The code below is working too slowly if table contains a lot of records. Any ideas?

    foreach (C1.Data.C1DataRow row in table.DataTable.Rows) row[0] = false;

    Regards, Andrew
  • 04-10-2008 6:15 AM In reply to

    Re: What is the quickest way to init a specified field for all rows in c1ExpressTable?

    Hi,

    > The code below is working too slowly if table contains a lot of records. Any ideas?
    >
    > foreach (C1.Data.C1DataRow row in table.DataTable.Rows) row[0] = false;

    This code works quickly on my machine. I don't see why it may work slowly.
    As an alternative way, you may update the field on server side. For example,

    using C1.Data.SchemaObjects;
    using System.Data.SqlClient;
    .....

    Connection c1conn = c1ExpressConnection1.DataSet.Schema.Connections[0];
    c1conn.Open() ;
    SqlConnection conn = (SqlConnection)c1conn.DbConnection;
    SqlCommand cmd = new SqlCommand("UPDATE MyTable SET MyField = FALSE", conn);
    cmd.ExecuteNonQuery();
    c1ExpressConnection1.Fill();
    cmd.Dispose();

    Though, it won't probably work faster because we have refill the whole
    dataset afterwards.

    Regards,

    -Andrey
  • 04-10-2008 7:39 AM In reply to

    Re: What is the quickest way to init a specified field for all rows in c1ExpressTable?

    Andrey, my table contains more than 50000 records and it works longer than 5 minutes. I can't update the field on server side, because it's calculated (I need it for displaying column with checkboxes in the grid).

    Regards, Andrew
  • 04-10-2008 10:56 AM In reply to

    Re: What is the quickest way to init a specified field for all rows in c1ExpressTable?

    > my table contains more than 50000 records and it works longer than 5 minutes

    Yes, the same issue occured on my machine when I tried to assign a value to
    a calculated field. This is wrong usage of calculated fields. They shouldn't be
    assigned from outside.

    There is a limitation in C1DataExpress: you can't add a field to the storage table.
    I see the only way out. Use C1SchemaDef and C1DataSet components instead
    of C1ExpressTable on that form. You can add a field to the corresponding simple
    table using the Schema Designer. Set the field properties as follow:

    InsertIgnore = True
    UpdateIgnore = True
    UpdateLocate = False
    UpdateRefresh = False
    UpdateSet = Never

    This field will be added to the dataset definition as a db field, not a calculated field.
    So, you can update it quickly within a cycle.

    See the attached sample for more details.

    Regards,

    -Andrey
  • 04-11-2008 2:32 AM In reply to

    Re: What is the quickest way to init a specified field for all rows in c1ExpressTable?

    Thanks, Andrey, for time you've found for me.

    Unfortunately I don't use C1SchemaDef nor C1DataSet. I tried to use them before, but it seemed not convenient for me, so I decided to stop treir using and set my choice on c1ExpressTable, it's enough for all of my projects and works well and fast.

    I'll try to change SelectCommandText adding a dummy field, like this: SELECT 0 as flag, id, name FROM table

    Hope it will work well.

    Regards, Andrew
Page 1 of 1 (5 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.