• Updating Changes to the Database [Janus GridEX WinForms Control v3.5 for .NET]

    Since a DataSet works with disconnected data, you must explicitly commit the changes in the dataset to the data source. This tutorial is intended to show you a simple example of how to do this:



    1) Add a button to the Form and Change its Name property to UpdateButton and its Text property to "Update"



    2) In the Click event of the UpdateButton, get a table with the rows that has changes, if the table is not empty, call the Update method in the DataAdapter to write those changes into the database.



    In VB:



    Dim changedRecords As System.Data.DataTable

    changedRecords = JSNorthWindDataSet.Products.GetChanges()

    If Not (changedRecords Is Nothing) AndAlso _

    (changedRecords.Rows.Count > 0) Then

    Dim message As String

    message = String.Format("You are about to update {0} record(s)." _

    + vbCrLf + "Do you want to continue?", changedRecords.Rows.Count)



    If MessageBox.Show(message, "GridEX Tutorial", MessageBoxButtons.YesNo, _

    MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then

    Try

    ProductsTableAdapter.Update(JSNorthWindDataSet.Products)

    Catch exc As Exception

    MessageBox.Show( _

    "An error occurred while trying to update the database:" + _

    vbCrLf + exc.Message + vbCrLf + vbCrLf + _

    "The rows with errors will appear in dark red.", _

    "GridEX Tutorial" , MessageBoxButtons.OK, _

    MessageBoxIcon.Exclamation)

    End Try

    End If

    Else

    MessageBox.Show("There are no changes in the Products table to update.", _

    "GridEX Tutorial", MessageBoxButtons.OK, MessageBoxIcon.Information)

    End If



    In C#:



    DataTable changedRecords;

    changedRecords = jsNorthWindDataSet1.Products.GetChanges();

    if (changedRecords != null && changedRecords.Rows.Count > 0)

    {

    string message;

    message = String.Format("You are about to update {0} record(s)."

    + "\n\rDo you want to continue?", changedRecords.Rows.Count);

    if (MessageBox.Show(message, "GridEX Tutorial",

    MessageBoxButtons .YesNo,

    MessageBoxIcon .Question) == DialogResult.Yes)

    {

    Try

    {

    productsTableAdapter1.Update(jsNorthWindDataSet1.Products);

    }

    catch (Exception exc)

    {

    MessageBox.Show("An error occurred while trying to update " +

    "the database:\n\r" + exc.Message + "\n\n\r" +

    "The rows with errors will appear in dark red." ,

    "GridEX Tutorial" , MessageBoxButtons.OK,

    MessageBoxIcon .Exclamation);

    }

    }

    }

    Else

    {

    MessageBox.Show("There are no changes in the Products

    table to update." , "GridEX Tutorial", MessageBoxButtons.OK, MessageBoxIcon.Information);

    }

    3) Press F5 and run the project.

    Source Of Information : Janus v3.5 Help Files for VS 2008


0 comments:

Leave a Reply