in

C1 Community

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

refill data objects in data library

Last post 03-05-2008 3:30 AM by albertsmus. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 03-04-2008 1:45 AM

    refill data objects in data library

    i use a data library object in my project. if i change the connection string on the run time i have to end the application and reopen it to access the new data. is it possible to access the data without closing the application?.

    i noticed  that when i run the project the CreateSchema event runs one when a dataset needs access to data. if i open a second form with another dataset the CreateSchema not runs again even if i change the connection string, i have to close the application and reopen it to access the new data.

    Thanks  for help

  • 03-04-2008 11:39 AM In reply to

    Re: refill data objects in data library

    Hi,

    I don't think that you need to recreate the whole schema just to change
    the connection string. You can use the DynamicConnections property
    of the C1DataSet to connect a different database. For example, see the
    attached sample. Here is some code from that sample.

    // switch to the second connection string
    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
    RadioButton2.CheckedChanged
    If RadioButton2.Checked And C1DataSet1.DynamicConnections.Count = 0 Then

    Dim conn As Connection = C1DataSet1.Schema.Connections(0).Clone()
    conn.ConnectionString = _
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\ComponentOne Studio.NET 2.0\common\NWIND.MDB;Persist Security
    Info=False"
    C1DataSet1.DynamicConnections.Add(conn)
    C1DataSet1.Fill()

    End If
    End Sub

    // switch to the first (original) connection string
    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
    RadioButton1.CheckedChanged
    If RadioButton1.Checked And C1DataSet1.DynamicConnections.Count > 0 Then

    C1DataSet1.DynamicConnections.Clear()
    C1DataSet1.Fill()

    End If
    End Sub

    If you still want to recreate the schema you may use the following undocumented trick:

    C1DataSet1.SchemaDefComp.SerializedSchema = Nothing

    or

    C1SchemaDef1.SerializedSchema = Nothing

    The schema will be recreated next time when you fill the dataset.

    Regards,

    -Andrey
  • 03-05-2008 3:30 AM In reply to

    Re: refill data objects in data library

    Thanks Andrey

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