Databases Reference
In-Depth Information
//Print value
Console.WriteLine("\nCustomer "+pname+" has cid "+cid);
}
}catch (Exception e)
{
Console.WriteLine(e.Message);
}finally
{
//Clean up the resources
reader.Close();
conn.Close();
}
}
Deleting customer entry
Deleting existing customer entry is done simply using DELETE statement with
WHERE clause for CID as shown in Example 6-16.
Example 6-16 Deleting a row from the Customer table
public static void Main(String[] args)
{
...
DB2Connection conn = null;
conn = ConnectDb(alias, userid, password);
...
rowsdeleted=DeleteCustomer(conn, cid);
Console.WriteLine("\nRows deleted : "+rowsdeleted);
...
}
public static int DeleteCustomer (DB2Connection conn, int pcid)
{
String delSQL="delete from customer where cid = "+pcid;
Console.WriteLine("\nDelete Stmt: \n"+delSQL);
DB2Command cmd = new DB2Command(delSQL, conn);
int rowsDeleted = cmd.ExecuteNonQuery();
Console.WriteLine("\nRows Deleted: \n"+rowsDeleted);
conn.Close();
return rowsDeleted;
}
Search WWH ::




Custom Search