Update a DataTable using a query
Posted: Fri 20 Sep 2013 22:23
Maybe this post does not belong to this forum, but I have already asked in ADO.NET forums without response. If this is the case, please disregard my question and I apologize for any inconvenience.
I have a DataTable (dtFuentes) that contains the following columns:
* fte_id
* fte_parent
* fte_porc
* fte_porc_aux
The field "fte_parent" can have the same value for several records in the DataTable and I want to update column "fte_porc_aux" based on certain criteria using a query like this:
UPDATE dtFuentes SET fte_porc_aux = porc_value WHERE fte_parent = parent_value
I will very much appreciate if someone provides a step by step procedure about how to achieve my goal showing connections, commands and so on.
I have tried the code below but it returns 0 rows affected and, using the debugger, I can see that there are several rows with fte_parent = 180.
String strSQL = "UPDATE dtFuentes SET fte_porc_aux = 99 WHERE fte_parent = 180";
// I have also tried using a connection like this defined some lines before.
// PgSqlCommand pgCmd = new PgSqlCommand(strSQL, pgConn);
PgSqlCommand pgCmd = new PgSqlCommand();
pgCmd.CommandText = strSQL;
dtFuentes.UpdateCommand = pgCmd;
Int32 intRecords = dtFuentes.Update();
Respectfully,
Jorge Maldonado
I have a DataTable (dtFuentes) that contains the following columns:
* fte_id
* fte_parent
* fte_porc
* fte_porc_aux
The field "fte_parent" can have the same value for several records in the DataTable and I want to update column "fte_porc_aux" based on certain criteria using a query like this:
UPDATE dtFuentes SET fte_porc_aux = porc_value WHERE fte_parent = parent_value
I will very much appreciate if someone provides a step by step procedure about how to achieve my goal showing connections, commands and so on.
I have tried the code below but it returns 0 rows affected and, using the debugger, I can see that there are several rows with fte_parent = 180.
String strSQL = "UPDATE dtFuentes SET fte_porc_aux = 99 WHERE fte_parent = 180";
// I have also tried using a connection like this defined some lines before.
// PgSqlCommand pgCmd = new PgSqlCommand(strSQL, pgConn);
PgSqlCommand pgCmd = new PgSqlCommand();
pgCmd.CommandText = strSQL;
dtFuentes.UpdateCommand = pgCmd;
Int32 intRecords = dtFuentes.Update();
Respectfully,
Jorge Maldonado