Hi i am trying to write a function which will update or insert into a table, this function can then be called up in different pages which will require a table in the database to be updated or inserted into. This is something similar which has been written
in PHP, however i am clueless when it comes to PHP,
newValues = array();
/////////////////////////////////////////////////////////////////////////////////////
// functions for building update and insert queries:
// * newValues is an array with the same structure as a record returned by mysql_fetch_assoc,
// i.e. columnName => value
function dbBuildUpdateQuery($tableName, $newValues, $idField, $idValue, $idField2 = '', $idValue2 = '', $idField3 = '', $idValue3 = '')
{
// returns SQL update query based on $newValues:
if (count($newValues) == 0)
return '';
$assignmentStrings = array();
foreach ($newValues as $columnName => $newValue)
$assignmentStrings[] = "$columnName='$newValue'";
$q = "update $tableName set ".implode(', ', $assignmentStrings)." where $idField='$idValue'";
if ($idField2)
$q .= " and $idField2='$idValue2'";
if ($idField3)
$q .= " and $idField3='$idValue3'";
return $q;
}
Hi i am still trying to convert the following code to asp.net i will appreciate it if somebody can help me do so, this is the code, thanks
$newValues = array();
/////////////////////////////////////////////////////////////////////////////////////
// functions for building update and insert queries:
// * newValues is an array with the same structure as a record returned by mysql_fetch_assoc,
// i.e. columnName => value
function dbBuildUpdateQuery($tableName, $newValues, $idField, $idValue, $idField2 = '', $idValue2 = '', $idField3 = '', $idValue3 = '')
{
// returns SQL update query based on $newValues:
if (count($newValues) == 0)
return '';
$assignmentStrings = array();
foreach ($newValues as $columnName => $newValue)
$assignmentStrings[] = "$columnName='$newValue'";
$q = "update $tableName set ".implode(', ', $assignmentStrings)." where $idField='$idValue'";
if ($idField2)
$q .= " and $idField2='$idValue2'";
if ($idField3)
$q .= " and $idField3='$idValue3'";
return $q;
}
PeterNwan
Member
70 Points
193 Posts
writing a function in c#
Oct 22, 2007 02:35 PM|LINK
Hi i am trying to write a function which will update or insert into a table, this function can then be called up in different pages which will require a table in the database to be updated or inserted into. This is something similar which has been written in PHP, however i am clueless when it comes to PHP,
newValues = array();
/////////////////////////////////////////////////////////////////////////////////////
// functions for building update and insert queries:
// * newValues is an array with the same structure as a record returned by mysql_fetch_assoc,
// i.e. columnName => value
function dbBuildUpdateQuery($tableName, $newValues, $idField, $idValue, $idField2 = '', $idValue2 = '', $idField3 = '', $idValue3 = '')
{
// returns SQL update query based on $newValues:
if (count($newValues) == 0)
return '';
$assignmentStrings = array();
foreach ($newValues as $columnName => $newValue)
$assignmentStrings[] = "$columnName='$newValue'";
$q = "update $tableName set ".implode(', ', $assignmentStrings)." where $idField='$idValue'";
if ($idField2)
$q .= " and $idField2='$idValue2'";
if ($idField3)
$q .= " and $idField3='$idValue3'";
return $q;
}
function dbUpdate($tableName, $newValues, $idField, $idValue, $db = "auto")
{
dbExecute(dbBuildUpdateQuery($tableName, $newValues, $idField, $idValue), $db);
}
function dbBuildInsertQuery($tableName, $newValues)
{
// returns SQL update query based on $newValues:
if (count($newValues) == 0)
return '';
$columnNames = array_keys($newValues);
return "insert into $tableName (".implode(', ', $columnNames).") values ('".implode("', '", $newValues)."')";
}
CANfunction dbInsert($tableName, $newValues, $db = "auto")
{
dbExecute(dbBuildInsertQuery($tableName, $newValues), $db);
}
PeterNwan
Member
70 Points
193 Posts
Re: writing a function in c#
Oct 22, 2007 03:07 PM|LINK
PeterNwan
Member
70 Points
193 Posts
Re: writing a function in c#
Nov 07, 2007 10:24 AM|LINK
Hi i am still trying to convert the following code to asp.net i will appreciate it if somebody can help me do so, this is the code, thanks
$newValues = array();
/////////////////////////////////////////////////////////////////////////////////////
// functions for building update and insert queries:
// * newValues is an array with the same structure as a record returned by mysql_fetch_assoc,
// i.e. columnName => value
function dbBuildUpdateQuery($tableName, $newValues, $idField, $idValue, $idField2 = '', $idValue2 = '', $idField3 = '', $idValue3 = '')
{
// returns SQL update query based on $newValues:
if (count($newValues) == 0)
return '';
$assignmentStrings = array();
foreach ($newValues as $columnName => $newValue)
$assignmentStrings[] = "$columnName='$newValue'";
$q = "update $tableName set ".implode(', ', $assignmentStrings)." where $idField='$idValue'";
if ($idField2)
$q .= " and $idField2='$idValue2'";
if ($idField3)
$q .= " and $idField3='$idValue3'";
return $q;
}
function dbUpdate($tableName, $newValues, $idField, $idValue, $db = "auto")
{
dbExecute(dbBuildUpdateQuery($tableName, $newValues, $idField, $idValue), $db);
}
function dbBuildInsertQuery($tableName, $newValues)
{
// returns SQL update query based on $newValues:
if (count($newValues) == 0)
return '';
$columnNames = array_keys($newValues);
return "insert into $tableName (".implode(', ', $columnNames).") values ('".implode("', '", $newValues)."')";
}
function dbInsert($tableName, $newValues, $db = "auto")
{
dbExecute(dbBuildInsertQuery($tableName, $newValues), $db);
}
vinz9969
Member
80 Points
25 Posts
Re: writing a function in c#
Dec 04, 2007 02:06 AM|LINK
Hi,
First you can use the PHP to ASP.NET 1.x Migration Assistant
to help you.
http://www.asp.net/downloads/archived/migration-assistants/php-to-aspnet/