Databases Reference
In-Depth Information
Console.WriteLine("\n XML Document to be inserted: \n " );
custXmlDoc.Save("Customer1.xml");
Console.WriteLine("\nDone creating customer info XML data. \n");
return custXmlDoc;
}
Updating existing customer information
Updating XML data in the CUSTOMER table will require use of the
cmd.Parameters.Add() method to add XML data to the UPDATE statement.
Customer's info XML data will be recreated using new modified information, then
UPDATE statement will be used to insert new data to existing CID (customer ID).
In Example 6-13, a new XmlDocument is created using changed/modified
customer information through CreateCustXML() method. The DB2Connection
object, CID, and XmlDocument object containing new info data will be passed to
UpdateCustomer() method for update.
Example 6-13 Updating the Customer table
public static void Main(String[] args)
{
...
int rowsupdated= 0;
XmlDocument newXmlDoc = new XmlDocument();
// Declare a DB2Connection
DB2Connection conn = null;
conn = ConnectDb(alias, userid, password);
newXmlDoc=CreateCustXML(pcid, pname, pcountry, pstreet, pcity,
pprov, ppcode, ptype, pphonenumb);
...
rowsupdated=UpdateCustomer(conn, cid, newXmlDoc);
Console.WriteLine("\nRows updated : "+rowsupdated);
...
}
public static int UpdateCustomer(DB2Connection conn, int pcid,
XmlDocument pinfo)
{
DB2Command cmd = conn.CreateCommand();
cmd.Parameters.Add(new DB2Parameter("@XMLData", pinfo.InnerXml));
String updtStmt="UPDATE customer SET cid = " + pcid +
" ,info = @XMLdata where cid ="+pcid+";" ;
Console.WriteLine("\nUpdate Stmt: \n"+updtStmt);
cmd.CommandText= updtStmt;
int rowsUpdated = cmd.ExecuteNonQuery();
Search WWH ::




Custom Search