in

C1 Community

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

SQL Queries and searching values in non primary keys fields

Last post 02-29-2008 4:50 AM by Undertaker. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 02-28-2008 7:37 AM

    SQL Queries and searching values in non primary keys fields

    Hi.

    I am developing on C#. Here is my questions.

    1. I using C1DataObjects. And I have in my schema I have one table, I fill it with data from database. And now I need to make some query to select data (not one row but many rows). For example select all users with Name = "Sample Name". I can write query to database SELECT * FROM TABLE WHERE Name = 'Name'. But I want to know can I make some search (something like query) using C1DataObject without reading from database again and make it with one or two commands ?

    2. Can I Delete many rows at one time (like DELETE query in SQL)  and then update this to database?

    3. In examples i found some code for adding row:

                            TableNamesGrid.AllowAddNew = true;
                            TableNamesGrid.MoveLast();
                            TableNamesGrid.Row += 1;
                            TableNamesGrid.Columns[0].Text = Id.ToString();
                            TableNamesGrid.Columns[1].Text = NewTableName;
                            TableNamesGrid.Columns[2].Text = IsDefault.ToString();
                            TableNamesGrid.UpdateData();
                            TableNamesGrid.AllowAddNew = false;

    But it throwing exception with message 'Modifying data is not allowed with current property settings' (I using TrueDBGrid linked with C1DataTableSource).
     

  • 02-28-2008 4:50 PM In reply to

    Re: SQL Queries and searching values in non primary keys fields

    > 1.

    Yes, it is possible to search values using the C1DataView component without reading
    from database again. Please take a look at the second sample (WindowsApplication2)
    within the attached archive. The most interesting part of that sample:

    private void button1_Click(object sender, EventArgs e)
    {
    // the next command searches the values
    c1DataView1.RowFilter = textBox1.Text;

    // this shows results in the grid
    dataGridView2.DataSource = c1DataView1;

    // next commands loop through the result rows and show the product names.
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i
    {
    if (i > 0)
    sb.Append(", ");
    sb.Append(c1DataView1[i]["ProductName"].ToString());
    }
    label3.Text = sb.ToString();
    }

    > 2.

    It is not possible to delete a group of rows at once. You have to loop through all rows
    and call the Delete method of the C1DataRow objects that should be deleted.

    > 3.

    That was a very strange example. If you want to add a row from code please use
    the CurrencyManager object instead of the C1TrueDBGrid. See the first
    sample in the attached archive (WindowsApplication1). Here is a code excerpt:

    private void button1_Click(object sender, EventArgs e)
    {
    CurrencyManager cm = BindingContext[c1DataTableSource1] as CurrencyManager;
    if (cm != null)
    {
    cm.AddNew();
    C1DataRow row = C1DataRow.FromDataItem(cm.Current);
    row["ProductName"] = "new product";
    row["QuantityPerUnit"] = "kg";
    row["Discontinued"] = true;
    row["UnitPrice"] = 25.5;
    cm.EndCurrentEdit();
    }
    }

    Regards,

    -Andrey
  • 02-29-2008 4:50 AM In reply to

    Re: SQL Queries and searching values in non primary keys fields

     Thanks a lot. )))

Page 1 of 1 (3 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.