cancel
Showing results for 
Search instead for 
Did you mean: 

Grid -> Database

Former Member
0 Kudos

Hi all,

I am having difficulties saving changes from my grid to the database.

I have a DataTable source filled by a select Query and displayed in my grid.

Now when I change some values on my grid, how do I get the changes to be saved in the Database?

Thanks,

Emmanuel

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Ok great, I got It.

Now if I work with a matrix I don't have to go through this method?

Is Databinding the Items to the concerned fields enough to save the changed data to the database?

Many thanks,

Emmanuel

Trinidad
Product and Topic Expert
Product and Topic Expert
0 Kudos

With a simple matrix you will also need to go line per line and update your objects by hand in the database.

It will be something like:

matrix.FlushToDataSource()

to copy the info from the matrix to the DBDataSoruce

Then you go over the DBDataSource (line per line) to read all info and you assign it to the appropriate proprerties of the object you want to update.

The only way to have it automaticaly done is to use UDOs. You have many information regarding UDOs in this forum, there are also many discussions on how to use DBDataSources.

Regards

Trinidad.

Answers (4)

Answers (4)

Former Member
0 Kudos

Understood,

Thanks for all your help,

Regards,

Emmanuel

Former Member
0 Kudos

Thanks for your help;

Here is what I am doing:

DataTable DT = oForm.DataSources.DataTables.Item("MyDataTable");
Grid oGrid = (Grid)oForm.Items.Item("MyGrid").Specific;
for (int RowIndex=0;RowIndex<oGrid.Rows.Count;RowIndex++)
{
  int DTRowIndex  = oGrid.GetDataTableRowIndex(RowIndex);
  if (DTRowIndex >=0)
  {
    for (int ColIndex=0;ColIndex<oGrid.Columns.Count;ColIndex++)
    {
      DT.GetValue(ColIndex,RowIndex);
    }
  }
}

But it is not updating any value in the DataBase. Is my code looking ok?

Rgds,

Emmanuel

Trinidad
Product and Topic Expert
Product and Topic Expert
0 Kudos

When you use the GetValue method you only read a value, you need to put this value in the corresponding object and after that Update the object to copy the information in the DB.

For example if the information you want to read and update in the DB is the name of a BP (you have a column with the BPCode and another with the BPName) then the code should be something like this:

oBP = oCompany.GetBusinessObject(oBusinessPartner)

if (oBP.GetByKey(DT.GetValue(BPCodeColIndex, RowIndex))
  oBP.Name = DT.GetValue(BPNameColIndex, RowIndex)
  oBP.Update()

Hope it helps

Trinidad.

Former Member
0 Kudos

Thank you Ad.

I don't see how I can do this manually though.

Is there a simple method to update the database according to a DataTable?

I'd really like to stick with a grid because I need to use a Collapsible view.

Rgds

Emmanuel

Trinidad
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

You have to go row by row and column by column by using the DataTable method <i>GetValue(column, rowIndex)</i>.

I don't see another way, if someone finds another easiest way please share it with us.

Regards

Trinidad.

AdKerremans
Active Contributor
0 Kudos

Hi Emmanuel,

The auto-update doesn't work with the grid only with the matrix, you have write it yourself if you want to use the grid.

Regards,

Ad